Sign in to follow this  
Hexed

OpenGL Lighting Issues (screenshots)

Recommended Posts

Hi I'm beginning to write an OpenGL program and everything is going great except I notice the scene lighting is... strange. It seems like the lighting changes depending on the current camera position and angle. That's the only way I can really explain it, so I shall include screenshots. Notice how the lighting on the teapot model changes as the camera moves around the object. Also notice 31337 pr0gr4mm3r t3xtur3z.

Share this post


Link to post
Share on other sites
Sure thing. I'll include anything that I believe to be relevant, if you need more just let me know. In order of execution...

From resource loading function:

glLightfv (GL_LIGHT1, GL_DIFFUSE, sector01.light[i].rgba);
glLightfv (GL_LIGHT1, GL_POSITION, sector01.light[i].pos);
glEnable (GL_LIGHT1);


From GL initialization function:

glShadeModel (GL_SMOOTH);
glEnable (GL_LIGHTING);


And I believe that's all I have for lighting code. One light is in this scene, positioned at [0,0,0]. And I also call glNormal3f for each poly in order to ensure correct lighting.

Share this post


Link to post
Share on other sites
That's what I thought at first too. I was using these calls in main GL drawing function:

glRotatef(-xrot, 1.0f, 0.0f, 0.0f);
glRotatef(-yrot, 0.0f, 1.0f, 0.0f);
glTranslatef(-xpos, -ypos, -zpos);


And I tried replacing that with gluLookAt(), but same results. wtf?

Share this post


Link to post
Share on other sites
From the screenshots it looks like the light gets rotated the opposite direction with the scene before translating. You should handle the light position as if it was just another vertex in the scene.
Try putting the glLightfv (GL_LIGHT1, GL_POSITION, sector01.light[i].pos); after the translating and before the rendering code.

Share this post


Link to post
Share on other sites
Erm this is not working. Wouldn't that translate the light with the camera anyway? It doesn't sound right to me, none of the tutorials I have read mention anything like that.

Share this post


Link to post
Share on other sites
tassu is correct, after u position the camera u must reposition the lights
check the redbook, the faq etc

Share this post


Link to post
Share on other sites
Thanks for the replies. Tassu's suggestion solved my problems, I just wasn't understanding that the lights needed to be handled basically the same as a vertex in the scene. Now I am trying to fix another lighting problem, and I believe the issue is that I'm not rotating and supplying the correct glNormal3f. Kind of annoying. :) Thanks guys.

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