Light with glColor and glEnable(GL_COLOR_MATERIAL)


After hours of tests to understand how it works I need help…

I tried to test the colors of the lights and materials but I waste my time : my results change with the order of the calls of the opengl functions…

For example this order :
define GL_LIGHT_MODEL_AMBIENT and light0
define geometry

If I move glEnable(GL_LIGHTING); from the begining after the definition of the geometry I obtain a very different result.
I tested that because I have read in a forum that glColor must be called before enabling the lighting. But I did not read any things like this in the opengl documentation.

So what is the correct order of the calls ?

Thanks in advance.


No answer means that the problem is in my code…

I have another question :
How is the color of the back faces calculated when culling is disabled and GL_LIGHT_MODEL_TWO_SIDE is FALSE ? (ie back faces to draw but no light calculation on back faces)
I obtain the same result than for the front faces with light. Is it the rule ?


You can call glColor whenever you like but you must call it just before you render your object. GL is a state machine. It remembers the call.
If glColorMaterial is giving you trouble, then don’t use it and don’t use glColor. Use glMaterial instead when you use lighting and use glColor when you aren’t using lighting.

When GL_LIGHT_MODEL_TWO_SIDE is TRUE, GL checks the sign of the dot product between the normal and the light vector. If it is negative, it flips the direction of the normal and does the lighting calculation as usual.

When GL_LIGHT_MODEL_TWO_SIDE is FALSE, it doesn’t flip the normal. Yes, you are right, you get the same result as for front faces.

glColor is used in an existing code ; That’s why I have to use it.

Ok, it is doing a rendering but with the same normal.
In my case (with cull face disabled) I have no gain to set GL_LIGHT_MODEL_TWO_SIDE to FALSE because it does a rendering. Setting it to TRUE will give a more “realistic” result.

Thanks for your answer.