I’ve created a small demo that uses two lights to light a tank. The main light, the “sun” rotates around a horizontal axis to give the impression of rising and setting. It lights the base of my tank fine but does not do so for the turret, which is rotating. No matter which angle the turret is at, the “sun” shines from a fixed side, where I would have liked the shading to change to reflect which side of the turret was lit while it rotates. My code is below. Can anyone point out what is wrong.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Clear screen and depth buffer.
glLoadIdentity(); // Clear the matrix.
glTranslated(CameraX, CameraY, -CameraZ);
// Position scene to camera.
glPushMatrix(); // Save current matrix.
glRotatef(Rot, 1, -1, 0); // Rotate light.
glLightfv(GL_LIGHT0, GL_AMBIENT, Light0Amb);
// Set light 0’s ambient value.
glLightfv(GL_LIGHT0, GL_POSITION, Light0Pos);
// Position light 0.
glPopMatrix(); // Restore current matrix.
… // Other stuff for second light as flash from barrel.
glColor3f(0.5823f, 0.5216f, 0.3623f); // Set tank colour.
glPushMatrix(); // Save current matrix.
glTranslated(0, -0.1, 0); // Position for turret.
glRotatef(tRot, 0, 0, -1); // Rotate turret.
glCallList(ImageOffset + gTANKTURRETDL);
// Draw turret and attachments.
glPopMatrix(); // Restore current matrix.
glCallList(ImageOffset + gTANKBASEDL);
// Draw tank base.Rot += 0.2f; // Increase angle of sun.
if (Rot >= 360) // Keep Rot between 0 and 360.
Rot -= 360;
else if (Rot < 0)
Rot += 360;
tRot += 2.5f; // Increment turret rotation.
if (tRot >= 360) // Keep turret rotation between 0 and 360.
tRot -= 360;
else if (tRot < 0)
tRot += 360;
Its like the turret rotation affects Light0 even thought it should have been fixed when I used glLightfv() earlier.
[Edit] Fixed a typo.
Another weird thing. Setting glListBase to ImageOffset then doing glCallList(gTANKBASEDL) does not work. Yet it draws above, and using glListBase to draw text works. I debugged it and found ImageOffset = 97 which means it’s correct. Any Ideas what went wrong?
[This message has been edited by Furrage (edited 04-29-2002).]