I’m making a small simulation game in OpenGL where there is a ball in a field and the camera is locked to viewing the ball from an angle from the top (see the screenshots below). Everything works fine, however, when the camera passes some point, the lighting on a wall fails. It becomes as if there are “no lights” in a newly created scene.
Here is the correct one:

Here is when the camera passes from some point, the lighting is reset on the left wall:

It doesn’t occur gradually. It suddenly happens when the camera is moving. Here is my code for drawing the wall:
glBindTexture(GL_TEXTURE_2D, brickTexture);
glCallList(wallObjectID);
where the list is defined earlier:
glNewList(wallObjectID, GL_COMPILE);
glBegin(GL_QUADS);
glNormal3f(0, 90, 0);
glTexCoord2f(0, 0);
glVertex3f(0, 0, 0);
glTexCoord2f(0, 1);
glVertex3f(0, level->length, 0);
glTexCoord2f(2, 1);
glVertex3f(0,level->length, 100);
glTexCoord2f(2, 0);
glVertex3f(0, 0, 100);
glNormal3f(90, 0, 0);
glTexCoord2f(0, 0);
glVertex3f(0, 0, 100);
glTexCoord2f(0, 2);
glVertex3f(level->width, 0, 100);
glTexCoord2f(2, 2);
glVertex3f(level->width, 0, 0);
glTexCoord2f(2, 0);
glVertex3f(0, 0, 0);
glEnd();
glEndList();
And here are the OpenGL settings that are initialized in the beginning of the program:
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DOUBLEBUFFER);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float pos[] = { -30, -30, 30 };
float intensity[] = { 1,1,1,1 };
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glLightfv(GL_LIGHT0, GL_SPECULAR, intensity);
glLightfv(GL_LIGHT1, GL_POSITION, pos);
glLightfv(GL_LIGHT1, GL_SPECULAR, intensity);
float diff[] = { 0.6f, 0.6f, 0.75f };
glLightfv(GL_LIGHT1, GL_DIFFUSE, diff);
…
What could be the cause of the problem? Thank you.
UPDATE: Don’t get confused by the shadow of the ball, it’s just a transparency-enabled texture that sits below the ball, it’s NOT a real shadow.
You haven’t set light’s position right. You’ve used 3D vector – position. But according to the function documentation you have to use 4D vector.
4th (w) component indicates if light is directional or point, 1 mean’s it is point light. Other values than 1 will result in improper translation, ex. w = 500 and you’ll translate 3 points, then your light moves 1500points.
Also you have to set each light’s position when you change ModelView matrix for world translation(camera move), because when you move world, light won’t move with world, that means light is always in front of camera, ie. it’s moving with( locked to ) camera. Read this.