OpenGL glEnable (GL_COLOR_MATERIAL) followed by glDisable (GL_COLOR_MATERIAL)

I was drawing a cube cube at the same time next to a textured cube with glDrawArrays() and found that when the lights are on, the textured cube becomes "a little brighter."

After some debugging, I found that the very first moment that glEnable(GL_COLOR_MATERIAL) , even if glDisable(GL_COLOR_MATERIAL) called after that, causes a “slightly brighter” effect on the textured cube!

Here is a brief description:

 glEnable(GL_COLOR_MATERIAL); glDisable(GL_COLOR_MATERIAL); (...) glDrawArrays(GL_QUADS, 0, n); 

If glEnable(GL_COLOR_MATERIAL) is not called at all, the cube is drawn in yellow. And if glEnable(GL_COLOR_MATERIAL) , even if followed by glDisable(GL_COLOR_MATERIAL) , the cube is drawn a little brighter than yellow, and I cannot return to the "original color of the darker yellow cube."

Could you tell me if this is the expected behavior?

+4
source share
1 answer

this is not exactly the expected behavior, but it is easy to fix. GL_COLOR_MATERIAL allows you to rewrite material properties with vertex colors. The mistake is that the colors not only correspond with each other according to the color specification of the vertices, but also according to the resolution of the color material (my guess is that this could have been done intentionally to prevent errors).

All you need to do to make your cube a little darker is to restore the material properties to default (which are likely to be diffuse and ambient colors) using glMaterialfv (). Here you can find the colors of the materials by default .

+1
source

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


All Articles