# 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);
camera->update() // call gluLookAt(camera position)

... objects to draw

glPushMatrix();
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glPopMatrix();

glSwapBuffers();
}


Thanks, Sam

##### Share on other sites
is light_pos in eye space? also, why are you pushing/popping matrix around setting the light position?

##### 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 on other sites
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

##### Share on other sites
Can you show the code for camera->update()?
Levi

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628320
• Total Posts
2982072

• 21
• 9
• 9
• 13
• 11