From what I read in the OpenGL documentation, OpenGL prefers the BGR format over RGB. However, if you configure the internal texture format as BGR, the texture will be white when rendering. When the internal format is set to RGB or RGBA, it is displayed correctly. The source format starts with BGR (loaded directly from the DIB).
glBindTexture(GL_TEXTURE_2D, id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, nClamp);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, nClamp);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, nMagFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, nMinFilter);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
The next line is the problem ... setting the internal format to GL_BGR makes everything all white ... a change to GL_RGB makes it display correctly
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGR, pTex->nWidth, pTex->nHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, pTex->pBuffer);
source
share