GL_COLOR_MATERIAL: how to disable?

Started by
3 comments, last by stein 19 years, 3 months ago
Hello, I call glEnable(GL_COLOR_MATERIAL); to render some coloured polygons. Then, I would like to disable it to render some textured polygons but glDisable(GL_COLOR_MATERIAL); doesn't work. The lighting is changed and glDisable(GL_COLOR_MATERIAL); doesn't reset it. How can I disable GL_COLOR_MATERIAL, so the lighting is the same as before calling glEnable(GL_COLOR_MATERIAL);? P.S. Even if you call glEnable(GL_COLOR_MATERIAL); and then imediatly glDisable(GL_COLOR_MATERIAL); without doing anything, lighting is changed.
Advertisement
If you enable GL_COLOR_MATERIAL, the DIFFUSE and SPECULAR parts of the material, is set to corespond to the current glColor.
If you want the default "lighting" restored, you should set the default values for those components.
Am I making sense?
| Stein Nygård - http://steinware.dk |
And how can I do that?
With glLightfv(GL_LIGHT0, GL_AMBIENT,&lightAmbient); and glLightfv(GL_LIGHT0, GL_DIFFUSE,&lightDiffuse); of course, thanks.
It's the ambient and diffuse parts of the material (and not the specular of course), so do like this:

float fAmbient[] = {0.2f, 0.2f, 0.2f, 1.0f};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, fAmbient);

float fDiffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, fDiffuse);

That should work :)
| Stein Nygård - http://steinware.dk |

This topic is closed to new replies.

Advertisement