Happy monday.
I'm trying to use a GIF or a 8 bpp BMP image image as a source for an OpenGL texture.
The code is working well for other types of image (24, 32bits image)
I'm loading the file with CImage, but I'm having problems figuring the format and type parameters of the glTexImage2D function.
Either I get a full black texture, or I get the wrong colors.
// will create black texture.
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, imageWidth, image.GetHeight(), 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, bits );
// will create greyscale image.
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, imageWidth, image.GetHeight(), 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, bits );
// will create texture with wrong colors.
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, imageWidth, image.GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE_3_3_2, bits );
I also tried different other combinations, either it crashes, or give the same bad results.
This is the code I have right now:
CImage image;
image.Load(fileName);
int imageBPP = image.GetBPP();
GLuint texture = 0;
glGenTextures(1, &texture);
glBindTexture( GL_TEXTURE_2D, texture );
BYTE* bits = static_cast<BYTE*>(image.GetBits());
bits += (imageHeight-1) * imagePitch;
if ( imageBPP == 32 )
{
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, bits );
}
else if ( imageBPP == 24 )
{
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, bits );
}
else if (imageBPP==8)
{
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, image.GetWidth(), image.GetHeight(), 0, ????, ????, bits );
}
else
{
}
Any Idea ?
Thanks
Max.
==========================
Following nv3 suggestion, I decided to convert the 8 bits image to a workable image.
Thanks.