View Full Version : Need help with Lighting and Colors

11-12-2000, 06:08 AM
I have a program that draws and rotates a 1 simple triagle with the color blue. Then I decided to make another program that is exactly the same as the one before but this time, using lighting. Now when i use lighting, the color alwayz white but lighting is working on it. How do i keep the blue color and have lighting with that instead of white i cant change?

11-12-2000, 07:44 AM
When lighting is enabled, the color is based on the current material properties rather than the current color. You can do one of two things. Either set the material's ambient and diffuse properties to blue, or have those properties follow the current color.

The first method would look something like so:

float blue[3] = {0.0, 0.0, 1.0};


The second method would be something like this:


The second method is generally more efficient if you need to change the material properties frequently.

11-12-2000, 09:09 AM
Ok so how would I apply this to my object?
Do i put like before glbegin (GL_TRIANGLE) or in between the glbegin and glend?

11-12-2000, 11:15 AM
You could put it anywhere after you initialize the OpenGL window and before you render your triangle. OpenGL is basically a state machine. If you set the current material properties to blue, it'll stay blue for everything you render until you change it. If you use the GL_COLOR_MATERIAL method, using glColor3f will set the specified properties to blue until you change them.

Just a note, there are actually four different types of material properties.
Ambient - affects how ambient light is reflected
Diffuse - affects how diffuse lighting is reflected
Specular - affects highlights. It's brightest along the direct angle of reflection
Emmision - Makes the surface appear to give off light of that color

11-12-2000, 11:20 AM
hey. thanks for your help. ok well, i tried different combinations using GL_DIFFUSE, GL_AMBIENT and so on, but GL_DIFFUSE is the one that i needed. BTW, where do i get info on all these other params?..and GL_EMMISSION, how would i use that to give off light and affect objects near it?

11-13-2000, 01:33 AM
There isn't any such thing as GL_EMULLSION (I don't think). Look in the red book in the section about lighting, that is one of the sections which is explained quite well.

11-13-2000, 06:56 AM
Check the red book again. There is a section on GL_EMMISSION. It's one of the last sections on the whole ambient/diffuse/specular explanation. It mentions that it would be good if you are creating objects that are supposed to be where the light comes from, such as lamps, etc. It's also documented well in MSDN.

Using GL_EMMISSION won't create an actual light that will cause nearby objects to light up. If you want to simulate that you can try placing a positional light in front of the surface.

11-13-2000, 06:58 AM
I actually misspelled GL_EMISSION in my last posts. Only 1 m. Oops. http://www.opengl.org/discussion_boards/ubb/smile.gif

11-13-2000, 08:44 AM
So then whats the use of GL_EMISSION? what does it do to your object?

11-14-2000, 04:38 AM
For one thing you can make it appear that your light is coming from an object rather than have it just look like the object is being lit by a light. I haven't actually played with it all that much, but I can see where it might be useful.