PDA

View Full Version : Lighting on non-textured objects.



nexusone
02-23-2002, 11:38 AM
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.

zed
02-23-2002, 01:32 PM
check the faq (right side of page at www.opengl.org (http://www.opengl.org) ie this site)
look for a question like 'ive turned on lighting + colours have gone'

Chuck0
02-24-2002, 04:15 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

chowe6685
02-24-2002, 04:37 PM
glEnable(GL_COLOR_MATERIAL)

nexusone
02-24-2002, 06:10 PM
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)

Furrage
02-25-2002, 06:40 AM
Why choose glEnable(GL_COLOR_MATERIAL) over glMaterial*(...) ?

chowe6685
02-25-2002, 08:22 AM
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

nexusone
02-25-2002, 08:44 AM
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).]

Furrage
02-26-2002, 08:24 AM
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.

Furrage
02-26-2002, 09:02 AM
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.