-
The light position must be set before the viewing transformation
GLfloat light_position() = { 0.0, 0.0, 0.0, 1.0
};
glViewport(0, 0, (GLint) w, (GLint) h); glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(40.0, (GLfloat) w/(GLfloat) h,
1.0, 100.0); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
...
static GLdouble ex, ey, ez, upx, upy, upz;
void display(void) {
glClear(GL_COLOR_BUFFER_MASK | GL_DEPTH_BUFFER_MASK);
glPushMatrix();
gluLookAt (ex, ey, ez, 0.0, 0.0, 0.0, upx,
upy, upz);
glutSolidTorus (0.275, 0.85, 8, 15);
glPopMatrix();
glFlush();
}
-
Both the light source and the viewpoint are moved to
the same location
-
The effective light position is changed because the
eye coordinate system has changed