glColorMaterial problem

I’m having odd problems with glColorMaterial. I used to have it able to work right, but now it seems to fail all the time and I can’t work out why.

Either all the colors on the scene show up wrong (as the first color drawn), or no colors show up, and everything is white or textured normally.

I use this peusdo-code

DrawTexturedObjects();

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

DrawNextColoredNonTexturedObject();
glDisable(GL_COLOR_MATERIAL);

Now what happens, is that I get the whole scene blue, which is the only color drawn in DrawColoredNonTextureObject. It seems that although I’m disabling gl color material, its still affecting things.

If I add glcolor4f(1.0, 1.0, 1.0, 1.0); before glDisable gl color material, then I get the whole scene white, and no colors drawn!

I’m stuck here, this is making no sense at all, any idea anyone?

A wierd thing, when I try to disable gl_Color_material, it actually stays enabled!!!

Can someone explain this for me, please???

May seem a bit patronising, so I apologise before-hand.

glColorMaterial will only work when lighting is enabled.

First thing to check is, Are you using lighting? If you just want to give an object colour and haven’t got lighting enabled, then just use glColor*(). Otherwise make sure lighting is enabled.

Normally when lighting is enabled, you can specify the material properties with

glMaterial*()

using the constants :

GL_AMBIENT
GL_DIFFUSE
GL_SPECULAR
GL_EMISSION
GL_AMBIENT_AND_DIFFUSE
GL_SHININESS

to set up how the light interacts with the material.

When glColorMaterial is enabled, it will simply take which one of the above values and any colour specified by glColor*() will affect the given material property of what is being drawn.

With GL_AMBIENT_AND_DIFFUSE enabled as the mode for GL_COLOR_MATERIAL. When you set the colour to be 1,1,1,1 , then all objects drawn will have an ambient material property of white and diffuse as white also. This will basically result in lighting having no affect on textured objects, and untextured objects will appear white. If your untextured objects are all one colour, then I wouldnt bother enabling GL_COLOR_MATERIAL at all , but use glMaterialfv().

As to why it will not disable, I have no idea. Chances are though that its a bug in your source, or a misplaced push and pop somewhere…

Hope thats of some help

[This message has been edited by Rob The Bloke (edited 12-26-2000).]

[This message has been edited by Rob The Bloke (edited 12-26-2000).]

Try moving your viewpoint a bit. Maybe you are drawing your objects right on the camera lens.