1

I'm trying to load and display a texture in Android NDK Program using OpenGL ES 2.0.

Image loading is working, but I'm trying to init a texture with glTexImage2D however it always throws a error: distrib/android-emugl//host/libs/Translator/GLES_V2//GLESv2Imp.cpp:glTexImage2D:1883 error 0x501

I'm getting problem on 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);

I am using 128x128 image size.

Please help me some one.

The codes are something like:

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 Answer 1

1

The parameter you've given for glTexImage2D, seems to be wrong.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.