enable/disable GL_COLOR_MATERIAL

Hi,

It seems to me that the following glEnable() only enables GL_SPECULAR, rather than both GL_SPECULAR and GL_AMBIENT_AND_DIFFUSE. Am I right? Besides, if I want to re-enable GL_SPECULAR color material after the glDisable() below, do I have to call glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR) again? Thanks for any advise. Tony

glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glColorMaterial(GL_FRONT_AND_BACK, GL_SPECULAR);
glEnable(GL_COLOR_MATERIAL);

glDisable(GL_COLOR_MATERIAL);

OpenGL is a state machine. glColorMaterial is used to set current material property that is set by glColor when GL_COLOR_MATERIAL is set. So by calling glColorMaterial twice in a row, you are basically setting that state twice in a row, so your first call is essentially ignored. Consider the following:

iColorMaterialState = GL_AMBIENT_AND_DIFFUSE;
iColorMaterialState = GL_SPECULAR;

If you had code like that, you wouldn’t expect iColorMaterialState to still contain the value of GL_AMBIENT_AND_DIFFUSE, now would you? glColorMaterial essentially works the same way.