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).
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?
In a BMP file colors are in BGR format not RGB… You should swap the bytes…
… or use BGR internal format (which will also give you higher upload speed).
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!
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 . 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.