# Why is my lighting translating too?

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

## Recommended Posts

A noob question, but it should mean for a nice and easy answer (hopefully)... Here's what's happening: I create a light source, then I do a translate and I create a sphere, but when I run my program, my light source has translated as well as the sphere. Here's a chunk (kindof pseudocoded) of my draw function: . . . LightPosition = [ 0, 0, 3 , 0 ]; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); glPushMatrix(); glTranslatef(-5.0f, 5.0f, 0); glutSolidSphere(1.0f, 10.0f, 10.0f); glPopMatrix(); glPushMatrix(); glTranslatef(5.0f, -5.0f, 0); glutSolidSphere(1.0f, 10.0f, 10.0f); glPopMatrix(); glFlush(); . . . The result looks like the spheres are lighted at the origin and THEN translated...what do I need to do to make them get translated first, and THEN get lighted? I expected that the first would look like the light was coming from the bottom right and the second would look like the light was coming from the top left, but they both look like the light's coming from straight ahead. Thanks in advance.

##### Share on other sites
Try to place the light after you translate.

##### Share on other sites
The man is right; when you specify your light's position will dictate how that position is transformed before lightning calculations take place.

##### Share on other sites
Change
LightPosition = [ 0, 0, 3 , 0 ];
to
LightPosition = [ 0, 0, 3 , 1 ];

The first is a directional light while you seem to want a point light. I'm really tired but I'm pretty sure your calling glLightfv in the right place.

##### Share on other sites
You were right on, Cocalus. All I had to do was change that 0 to a 1 and it started working perfectly. Thanks!

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 12
• 10
• ### Forum Statistics

• Total Topics
632575
• Total Posts
3007154

×