glTexImage2D使用OpenGL ES 2.0抛出错误0x501 Android NDK程序

时间:2016-03-04 05:49:08

标签: android opengl-es android-ndk

我尝试使用OpenGL ES 2.0在Android NDK程序中加载和显示纹理。

图像加载正在运行,但我尝试使用glTexImage2D初始化纹理,但它总是抛出错误:distrib / android-emugl // host / libs / Translator / GLES_V2 // GLESv2Imp.cpp:glTexImage2D: 1883错误0x501

我在glTexImage2D上遇到问题

glTexImage2D(GL_TEXTURE_2D,0,texture [0] .bpp / 8,texture [0] .width,texture [0] .height,0,texture [0] .type,GL_UNSIGNED_BYTE,texture [0] .imageData) ;

我使用128x128图像尺寸。

请帮助我一些。

代码类似于:



int LoadGLTextures()    // Load Bitmaps And Convert To Textures
{
    int Status=false;                                // Status Indicator

    if (LoadTGA(&texture[0], "/sdcard/BG.tga"))
    {
        Status=true;                                 // Set The Status To TRUE

            // Typical Texture Generation Using Data From The TGA
            glGenTextures(1, &texture[0].texID);            // Create The Texture
            glBindTexture(GL_TEXTURE_2D, texture[0].texID);
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

            glTexImage2D(GL_TEXTURE_2D, 0, texture[0].bpp / 8, texture[0].width, texture[0].height, 0, texture[0].type, GL_UNSIGNED_BYTE, texture[0].imageData);

            if (texture[0].imageData)                 // If Texture Image Exists
            {
                free(texture[0].imageData);                // Free The Texture Image Memory
            }
        }
    return Status;                                  // Return The Status
}


bool LoadTGA(Texture * texture, char * filename)             // Load a TGA file
{
    FILE * fTGA;                                    // File pointer to texture file
    fTGA = fopen(filename, "rb");                       // Open file for reading

    if(fTGA == NULL)                                 // If it didn't open....
    {
        return false;                                         // Exit function
    }

    if(fread(&tgaheader, sizeof(TGAHeader), 1, fTGA) == 0)             // Attempt to read 12 byte header from file
    {
        if(fTGA != NULL)                                       // Check to seeiffile is still open
        {
            fclose(fTGA);                                      // If it is, close it
        }
        return false;                                         // Exit function
    }

    if(memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)             // See if header matches the predefined header of
    {                                                     // an Uncompressed TGA image
        LoadUncompressedTGA(texture, filename, fTGA);                 // If so, jump to Uncompressed TGA loading code
    }
    else if(memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)      // See if header matches the predefined header of
    {                                                     // an RLE compressed TGA image
        LoadCompressedTGA(texture, filename, fTGA);                      // If so, jump to Compressed TGA loading code
    }
    else                                                   // If header matches neither type
    {
        fclose(fTGA);
        return false;                                               // Exit function
    }
    return true;                                             // All went well, continue on
}




1 个答案:

答案 0 :(得分:1)

你为glTexImage2D提供的参数似乎是错误的。

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture[0].width, texture[0].height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)texture[0].imageData);