PDA

View Full Version : lighting problem



modest
04-25-2004, 01:09 PM
hi. I tried my first lighting using nehe's tutorial. my scene has ploygons having gradient colors (different colors at each corner). When I tried lighting everything become gray at the same tone. what is wrong with my code? any help please?


glShadeModel(GL_SMOOTH);
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightPosition[]= { 0.0f, 0.0f, 20.0f, 1.0f };
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);

chowe6685
04-25-2004, 01:42 PM
glEnable(GL_COLOR_MATERIAL);

Platinum Rogue
04-26-2004, 01:09 AM
Lighitin in OPenGL doesnt go that way. Just like in real life, the color of an object is decided by the actual color of the material of the object and the light falling on it.
What u must do is set the material properties of the object so that it reflects/absorbs/transmits the right amount of light that is specified by these materail properties.
Alternatively u can use color tracking which allows you to set the material properties by specifying only the color of the object.
Thats what GL_COLOR_MATERIAL does.

Try going through the online veriosn of the red book or the blue book available on openGL.org.