Light working at origin, not elsewhere

Started by
3 comments, last by levjs 18 years, 1 month ago
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:

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();
}


Thanks, Sam
Advertisement
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
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
"ok, pac man is an old gameand, there are faces which is eatin up shits" - da madface
Can you show the code for camera->update()?
Levi

This topic is closed to new replies.

Advertisement