Lighting on non-textured objects.

I have a blue cube and I want to add lighting to the scene.
When I turn on the gllight func the cube’s color is gone, leaving the cube white on the sides with the light and a dark gray on the other sides.

I know if I use a texture the cube it looks correct with that texture. If you are using lighting does a plain color need to be maped like a texture to the object.

check the faq (right side of page at www.opengl.org ie this site)
look for a question like ‘ive turned on lighting + colours have gone’

have you tried using the glColor4f function to set the color you wanted to apply to the cube?

another thing to check are the current material parameters (glMaterial)

just look up those function in the gl spec… maybe it will help

glEnable(GL_COLOR_MATERIAL)

After posting my message and digging through my Opengl book, I found it that command…
thanks anyway…

Originally posted by chowe6685:
glEnable(GL_COLOR_MATERIAL)

Why choose glEnable(GL_COLOR_MATERIAL) over glMaterial*(…) ?

glEnable(GL_COLOR_MATERIAL) is easier especially if you are already using glColor in your program, it saves time changing the code. Also glColor is faster if you are changing only one aspect of the color, which is typically the case

Speaking of glMaterial, in which I still not up on it 100%. At first I started using it to try and get the color back.

Is there a “GL_COLOR” flag for the glMaterial or call for setting the material color?

Also how about using “glColorMaterial” and “glColor”?

Originally posted by Furrage:
Why choose glEnable(GL_COLOR_MATERIAL) over glMaterial*(…) ?

[This message has been edited by nexusone (edited 02-25-2002).]

[This message has been edited by nexusone (edited 02-25-2002).]

If I remember right, Material colours can have different colours for different properties, namely ambient, diffuse, emissive and specular. So when you call glMaterialColor*() you can set any of these properties. You can make a metal object very shiny, or a neon object bright, regardless of the light settings. Each attribute has a default setting and if I’m correct most people simply go about changing only the ambient component of the material colour, which would be the same as glEnable(GL_COLOR_MATERIAL) then using glColor*(). So in that respect using glEnable() and glColor*() would be faster, but the other way gives you more options.

Originally posted by nexusone:
Is there a “GL_COLOR” flag for the glMaterial or call for setting the material color?
Also how about using “glColorMaterial” and “glColor”?

glMaterial*(…, GL_AMBIENT_AND_DIFFUSE, …) is the closest thing I can think of to a “GL_COLOR” flag. glMaterialColor*() is the same as calling glMaterial*() with GL_AMBIENT_AND_DIFFUSE.

You have to enable GL_COLOR_MATERIAL before your can use glColorMaterial*(). This tells OpenGL that when you call glColor*() you’re refering to the colour component specified in glColorMaterial. By default this is GL_AMBIENT_AND_DIFFUSE, which is the same as the glMaterial*() call above but as suggested faster. I haven’t tested them to compare though.