From what I've read in the OpenGL documentation, OpenGL prefers BGR format over RGB. However, when setting the texture's internal format as BGR, the texture is all white when rendering. When the inte开发者_如何学编程rnal format is set to RGB or RGBA it displays properly. The source format is BGR to begin with (loaded directly from 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 following line is the problem... setting the internal format to GL_BGR makes everything all white... changing to GL_RGB makes it render correctly
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGR, pTex->nWidth, pTex->nHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, pTex->pBuffer);
From the glTexImage2D man page, GL_BGR is not a internalFormat, just a format.
You should check for GL errors since that would've catched this error. What you read about "OpenGL prefering BGR" is false.
精彩评论