PDA

View Full Version : enable/disable GL_COLOR_MATERIAL



jyoung77
05-23-2003, 02:08 PM
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);

Deiussum
05-27-2003, 04:25 AM
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.