Apologies for yet another spotlight question. I have the following problem. I use a camera transform to move my view around. I am just trying to use a spotlight on a well tesselated plane.
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(camera_transform.inverse());
GLfloat lightPos[] = {0, 10, 40, 1};
GLfloat lightDir[] = {0, -1, -1};
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDir);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 30);
glBegin(GL_QUADS);
// Send out the quads which form the plane...
glEnd();
Now everything works like I expect, I move the view around and the spotlight stays where it is meant to, it lights up the correct amount of the plane based on its position and the SPOT_CUTOFF value. Also, I can turn the direction of the light around using the lightDir vector, and it moves like it should…
But if I try to move the spotlight direction so that it points in the positive z-drection, it will not illuminate anything. That is, whenever the lightDir vector has a component in the +z-direction, only those vertices which lie in the -z space relative to the lights position will be illuminated. So if I point the light straight down, I get a semicircle of illumination, with no illumination in the +z direction (the plane is large enough so that vertices should be lit).
If I rotate the plane itself instead of the light direction, only those vertices which were originally in the -z space relative to the light position will be lit - so the illumination does not stay a constant shape as the plane rotates underneath it.
It is not a problem with the plane normals, since I can move the light position around, and light up more of the plane. However, it never lights up anything at -z-values relative to the light position. I know that should give me a huge clue to what the problem is, but I just can’t figure it out.
Any help greatly appreciated!