Sign in to follow this  
sandy_bence

Light working at origin, not elsewhere

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this