PDA

View Full Version : details about glColorMaterial



adrien
09-20-2005, 12:46 AM
hello,
i'm using the followinf commands to specify the action of the next glColors operations :

float theBackColor[4]; theBackColor[0] = 0.f; theBackColor[1] = 0.f; theBackColor[2] = 0.f; theBackColor[3] = 1.f; glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, theBackColor );
glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, theBackColor); glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, theBackColor); glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, theBackColor);

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);

It works on some video cards, but on some others, a previously used color is also used.

I found that specifying glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_D IFFUSE); solves the problem.
And also, if I call glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE); before calling glEnable(GL_COLOR_MATERIAL);, the result is correct.

Is is something known that one must call glColorMaterial BEFORE enabling GL_COLOR_MATERIAL ?
And why is-it card dependant ?

thanks much
Adrien

memfr0b
09-20-2005, 02:27 AM
Yes, glColorMaterial has to be called before calling glEnable(GL_COLOR_MATERIAL). If you don't, the behaviour is not specified. Some drivers/cards just happen to not care about the order, so you sometimes get away with it.

adrien
09-20-2005, 02:39 AM
thanks much, but how did you know that ? I didn't read it anywhere...

memfr0b
09-20-2005, 02:53 AM
It's mentioned in the manual page for glColorMaterial under NOTES, second paragraph.

glColorMaterial (http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/colormaterial.html)

Overmind
09-20-2005, 02:55 AM
From the OpenGL 1.5 spec, page 62:

For instance,
calling
ColorMaterial(FRONT, AMBIENT)
while COLOR MATERIAL is enabled sets the front material acm to the value of the
current color.Also there's a data flow diagram on the next page that seems a very clear description of what is happening. Also there's no mention about an "active" copy of the state like in the VBO spec.

This sounds to me that glColorMaterial should work after GL_COLOR_MATERIAL is enabled, it's very well defined what should happen. Could be a driver bug... Or am I misinterpreting the spec here?

Relic
09-20-2005, 03:44 AM
Originally posted by memfr0b:
Yes, glColorMaterial has to be called before calling glEnable(GL_COLOR_MATERIAL). If you don't, the behaviour is not specified. Some drivers/cards just happen to not care about the order, so you sometimes get away with it.Wrong. Of couse it is specified and the default is (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE).

Pitfall #14 explains why you better set it first and enable it afterwards:
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
I'd recommend to do this for any enable.