Setting separate material properties for different objects in OpenGL

You should put:

glEnable(GL_COLOR_MATERIAL);

As the first thing in your render function, then set the light parameters:

glDisable(GL_COLOR_MATERIAL);
glPushMatrix();

Then set the properties of the material and call the object. All the objects from now on will have this property, if you want to use another material on another object just type:

glDisable(GL_COLOR_MATERIAL);

again, before modeling the second object and so on. If you still have questions, just ask.


First, your example code looks reasonable and your objects should indeed have different materials.

But keep in mind that you only change the diffuse material color for your second object, as you set exactly the same specular colors and shininess values for both objects. And the ambient of the second object is also the same like for the first, as you only enable color material for the diffuse channel, so the ambient is unchanged from the first object, as OpenGL is a state machine.

So the only material difference between the objects is their diffuse color and this difference is (101, 30, 26). So can it be, that this difference is just outweighted by the ambient and specular terms that are completely equal and is therefore just too small for you to notice? Try completely different materials and see if there is really no difference.

Tags:

C++

Opengl