View Full Version : lighting problem!!!

01-22-2004, 07:46 PM
hi friends...
i was trying to put lighting on my simple object in openGL....i made a cube (plane colors cube...no bitmap..no texture) using nehe's tutorial and switch on the light, the moment i switch it on...whole cube become either black or white..or of light color..and all original color ( six on six diff faces disappears)....
what i wanted was ...that light will just help to make color shine...depending on the position of source....
how can i actually make diff sober and plane faces look glow...and that too with help of light source..
lots of thanks in advance!!

01-23-2004, 02:41 AM
Don't know the cube example, but for lighting to work you need to specify normal vectors pointing from the front face.

For the cube you need six normals pointing in the unit directions.
Define six quads, vertices in counter clock directions when looking from the outside (=> front faces), each of them using their correct normal pointing to you if looking on the front face.
Define materials and light, use a positional light and local viewer to get nicer specular highlights.
If the highlights should be on the cube faces you need to use a higher tesselation per cube face to catch specular highlights, as lighting is done per vertex.

01-23-2004, 10:10 AM
Also note that there is a difference in how the color gets specified with lighting activated or deactivated. With lighting disabled the color comes from glColor calls, with lighting enabled it (basically) comes from glMaterial calls...

01-28-2004, 05:16 PM
To get your glColor calls to work with lighting on use Color Material (Color Tracking).

Firts enable it:
Then set it up:

How this is works is. the first paramater is what face the color material will be applied too. The second parameter says what material property will bind to glColor calls. In the example above, now every time you use glColor that color will set the diffuse property of the material.