Lighting problems

in my draw function i have:

glRotatef(xrot,1.0,0.0,0.0);
glRotatef(yrot,0.0,1.0,0.0);
glTranslatef(xtran,ytran,ztran);
DrawCube();

and i use the mouse and keyboard to change the variables to make it like you can walk around but when i move around the light does not move around with me?
how can i slove this?

When do you set the light source’s position because this is important?

If you set the position before applying the viewing transformations then you are setting the light’s position relative to the camera; if you set the position after the viewing transformations you are setting the light’s world position.

Just remember that the light position is multiplied by the current modelview matrix at the time you set the position.

If you want the light to move with the camera, set the position before the viewing transforms - after you set modelview to identity (or you could just do it once at initialisation if it never moves).

[This message has been edited by T (edited 01-20-2003).]

ok i have put the gllightfv after the glTranslatef but still when i look up and down the cube changes colour
what is happening here?

Do you have any specular contribution in the material and light source parameters. The specular contribution is view point dependent and therefore will change when the eye moves.

[This message has been edited by T (edited 01-21-2003).]