Sign in to follow this  
J1NX

Why is my lighting translating too?

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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!

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