OpenGL GL_BGR does not work for internal texture format

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);
+3
source share
1 answer

From the glTexImage2D page , GL_BGR is not an internal format, but simply a format.

You should check for GL errors as this would result in an error. What you read about "OpenGL Preferring BGR" is wrong.

+2
source

Source: https://habr.com/ru/post/1786614/


All Articles