PDA

View Full Version : lighting problem!!!



01-22-2004, 08: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!!
-prafs

Relic
01-23-2004, 03: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.

Overmind
01-23-2004, 11: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...

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

Firts enable it:
glEnable(GL_COLOR_MATERIAL);
Then set it up:
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);

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.

Regards,
Troy