Jump to content
  • Advertisement
Sign in to follow this  
sandy_bence

Light working at origin, not elsewhere

This topic is 4511 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
is light_pos in eye space? also, why are you pushing/popping matrix around setting the light position?

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!