PDA

View Full Version : Lighting Problems



Polygon
01-31-2001, 12:04 PM
This is my first attempt at bringing lighting into an opengl program. Right now as it looks, it has a room with no cieling and a table in the middle. I wanted to try directional lighting. I went through a tutorial and set up the light properties, and I also added the normals to all polygons in the scene. So far I have encountered two major problems. I am using a world camera(ie camera is 0,0 and everything else moves around it). If I move forward or back the lighting doesnt change, but when I look up and down the lighting gets brighter and darker. Here is the snip that does camera angles.

glRotatef( angle[0], 1.0, 0.0, 0.0 );
glRotatef( angle[1], 0.0, 1.0, 0.0 );
glRotatef( angle[2], 0.0, 0.0, 1.0 );
glTranslatef( pos[0], pos[1], pos[2] );

this is in the display function and the angles are set in the idle function. I cant figure out how the two are related since lights positions are absolute. Also here is the code for setting up the light in the initwindow()

glShadeModel(GL_SMOOTH); // Set the shading model
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Set the polygon mode to fill

glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

glLightfv(GL_LIGHT0, GL_POSITION, position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

anyone see anything wrong here? My last problem is the legs of the table...no matter what i set the normal to i cant get any light to bounce off of it. Please and suggestions would be greatly appreciated!

Derek Brinkmann