init()
{
...
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
glLightfv(GL_LIGHT0, GL_SPECULAR, white);
...
}
drawScene()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
camera->update() // call gluLookAt(camera position)
... objects to draw
glPushMatrix();
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glPopMatrix();
glSwapBuffers();
}
Light working at origin, not elsewhere
When the light position is at (0,0,0), the lighting is working fine. If I initialise the light at a different position, the lighting doesn't seem to work:
Thanks, Sam
is light_pos in eye space? also, why are you pushing/popping matrix around setting the light position?
Unless the light needs to change positions in the scene, or if you don't want rotations to affect it's position, you should just place
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
In the init function.
If you want to leave it as is, then I believe you need
glTranslatef(0,0,0);
before the line
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
Or else, you're just drawing where-ever the it happens to draw at. See if that works.
Levi
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
In the init function.
If you want to leave it as is, then I believe you need
glTranslatef(0,0,0);
before the line
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
Or else, you're just drawing where-ever the it happens to draw at. See if that works.
Levi
Call your glLightf() function before you use camera->update()
Otherwise, your light will be set up in relation to wherever your camera is located, since that becomes the new origin
Otherwise, your light will be set up in relation to wherever your camera is located, since that becomes the new origin
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement