I just started working on implementing lights (direction) in my application. All is working ok except when I use gluLookAt to move the camera the lighting is affected by the movement even though there is no specular turned on. Is there any rule-of-thumb cause for this problem that a beginner should know?
Could it have anything to do with PROJECTION matrix “abuse”?
Position or direction of the light is multiplied by modelview matrix that was active at time when the light position or direction was specified.
Thank you for your quick response but I’m not sure I understand how that could be the problem. The first time I use gluLookAt is far after I instruct the light position and set the model view matrix.
—update game and camera state
Entire OGL lighting operates in eye space (space after application of the modelview matrix) and light positions are also stored in this space. Because light positions are stored in eye space, they will remain in the same position relative to the camera even when the modelview matrix changes. This is what you are seeing.
To keep them at fixed position in world space you need to respecify theirs position each time the position of the camera (the “view” part of the modelview matrix) changes so the main loop should look like:
// Load view part of the matrix.
// Respecify the lights.
glLightfv( GL_POSITION, world space position )
// Apply model transformations and render geometry.
Ok I fiddled with code with your help in mind and got it working.