Spot Light / Specular Lighting seems incorrect

Hi, I am programming OpenGL with Python.

Basically I have a spot light pointing at a wall. The direction of the spotlight, the direction of the camera, and the direction of the normal on the wall are collinear.

As I move the camera away from the wall, the light (originally in the middle of the wall), moves upward and to the right.

I attached 3 pictures of what my camera looks like at various distances from the wall, with the camera coordinates displayed.

Why doesn’t the light stay in the middle of the wall as I move away from it?

Here is my lighting function:
(I can show the rest of my code if needed)

def lighting():

glLightfv(GL_LIGHT1, GL_POSITION, [5.0,0.0,0.0,1.0])
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION,[-1.0,0.0,0.0])
glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 60.0)
glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 128.0)





The light position is multiplied with the modelview matrix at the moment glLightf is called with GL_LIGHT#_POSITION. If you are passing world-space lights, then the modelview matrix at that point needs to have a world-to-eye/camera/etc matrix on it.

Awesome, I fixed the problem by putting the position and direction functions in my display/render function.

Now the position and direction of the light are reset every frame. Before they were only set once at the beginning of the program.