Lighting with gluLookAt

Hey all,

This is the first time I’ve had lighting on while calling gluLookAt, and I got some weird results. I know gluLookAt messes with the model-view matrix, I’m not exactly sure what it does, though. I wanted a directional light (the sun) at (1,1,1). It would come down over my right shoulder. It did before I put the gluLookAt in there. Is there any way to determine what the location should be if I want the same/similar lighting effect?

Just remember that when you specify a light posiion, it is multiplied by the model view matrix. So, if you want your light vector unmodified, load an identity matrix before you set the position:

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
//set light position…
glPopMatrix();

Originally posted by RadicalHumility:
[b]Just remember that when you specify a light posiion, it is multiplied by the model view matrix. So, if you want your light vector unmodified, load an identity matrix before you set the position:

glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
//set light position…
glPopMatrix();[/b]
Well,the light vector will be unmodified,but the whole scene will be rotated around the camera,thus the lighting will change when the camera pos/orientation change.What you must do is this:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

SetCameraPos();//Use gluLookAt,glRotate,anything
SetLightPos();

glPushMatrix();
glTranslatef(objx,objy,objz);
DrawAnObject();
glPopMatrix();