PDA

View Full Version : color loss with OpenGL textures



xargon
02-02-2006, 05:13 AM
Hi everyone,

I am having a strange problem when loading a bitmap as a texture. Some color channels are inverted or changed... Blue looks a weird muddy green etc.

Here is the code, I used to generate the texture. The bitmaps are quite big (1024 X 768).

glGenTextures(1, &m_Texture);
glBindTexture(GL_TEXTURE_2D, m_Texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, bitmap.bmWidth, bitmap.bmHeight, GL_RGB, GL_UNSIGNED_BYTE, bitmap.bmBits);

I do not think I have done anything out of the ordinary. Any thoughts?

Cheers,
xargy

uruk
02-02-2006, 08:14 AM
In a BMP file colors are in BGR format not RGB... You should swap the bytes...

Obli
02-02-2006, 08:46 AM
... or use BGR internal format (which will also give you higher upload speed).

xargon
02-02-2006, 11:42 PM
Hi guys,

Thanks for the replies!

I tried using GL_BGR_EXT extension, but then the bitmap does not load. Is there some other extension that I need to use?

Cheers and thanks!

xargy

Bob
02-03-2006, 12:00 AM
If you did what Obli said and put GL_BGR in the internal formqat, it won't work. Internal format should be GL_RGB as in your first post. GL_BGR should be put in the source format, because the actual image data you provide is BGR, not RGB.

Could also be an issue with gluBuild2DMipmaps. Consider using glTexImage instead since it's more up to date with newer features. If you need mipmapping, use automatic mipmap generation (http://oss.sgi.com/projects/ogl-sample/registry/SGIS/generate_mipmap.txt) . However, that may not work properly if the image is not a power of two along some dimension and your driver does not support ARB_texture_non_power_of_two or OpenGL 2.0.

Obli
02-03-2006, 07:13 AM
Originally posted by Bob:
If you did what Obli said and put GL_BGR in the internal formqat, it won't work. Internal format should be GL_RGB as in your first post. GL_BGR should be put in the source format, because the actual image data you provide is BGR, not RGB.
Sorry, I messed up again.