Sign in to follow this  
Emiug

Lighting Woes

Recommended Posts

Hi, im having problems with my lighting solution in my application. The light initially displays as expected, but as more objects are added into the scene the light seems to move position. i have a fraps of what the problem is below: http://www.emiug.co.uk/RTS/DevShots/BuildTest2.wmv Below is the code that i use to define the lighting. GLfloat light_position[] = { 0,50.0,0,1.0 }; //defines the light posistion GLfloat mat_specular[] = { 0.0 , 0.0 , 0.0, 1.0 }; //set the materials specular glEnable(GL_LIGHTING);//turn off lighting glEnable(GL_LIGHT0); //enable a light glLightfv(GL_LIGHT0, GL_POSITION, light_position); //add in the light glLightfv(GL_LIGHT0, GL_SPECULAR, mat_specular); //give the lighting the specular settings [Edited by - Emiug on June 9, 2007 12:46:16 PM]

Share this post


Link to post
Share on other sites
yes i am,

my draw scene method looks like this at the moment.


void DrawScene(void)
{

glPushMatrix();

glRotatef(-cameratilt,1.0f,0.0f,0.0f); //camera tilting
glRotatef(rotationx,0.0f,0.0f,1.0f); //rotate the scene



gluLookAt(camerax,cameray,cameraz, camerax + 5 ,0 ,cameraz, 0.0f,1.0f,0.0f); //setup the camera
GLfloat light_position[] = {0,50.0,400,1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position); //add in the light
DrawUnits();
terra.DrawTerrain(); //draw the terrain
terra.DrawWater();

//defines the light posistion

glPopMatrix();

glRotatef(-10,1.0f,0.0f,0.0f); //generic tilt of camera to give model definition

}

Share this post


Link to post
Share on other sites
Try doing all your lighting stuff first before the push pop matrix?
Otherwise it's position's being effected by the model matrix stack.

Share this post


Link to post
Share on other sites
Yes, previously i did this, and this is what caused my light to move when i rotated the camera.

My main issue is when i create the other objects, the lights seem to turn off until i draw another different class object.

Share this post


Link to post
Share on other sites
Are you perhaps setting different materials on the other units and those material settings are being passed on? I'm guessing though. By other objects do you mean different types of things you render in the scene? Is there something you can draw again and again without effecting the lights?

Share this post


Link to post
Share on other sites
It seems that with each model that is build, the light moves.
I tested not drawing the models, and the light stayed in its absolute position.
im guessing the lighting might be translated with each model being drawn?


Another video of lighting jumping around
http://www.emiug.co.uk/RTS/DevShots/buildtest3.wmv

Share this post


Link to post
Share on other sites
Try this?


glPushMatrix();

GLfloat light_position[] = {0,50.0,400,1.0 };

glLightfv(GL_LIGHT0, GL_POSITION, light_position); //add in the light
glPopMatrix();

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