Lighting Woes
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]
yes i am,
my draw scene method looks like this at the moment.
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 }
Try doing all your lighting stuff first before the push pop matrix?
Otherwise it's position's being effected by the model matrix stack.
Otherwise it's position's being effected by the model matrix stack.
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.
My main issue is when i create the other objects, the lights seem to turn off until i draw another different class object.
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?
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
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
Try this?
glPushMatrix();
GLfloat light_position[] = {0,50.0,400,1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position); //add in the light
glPopMatrix();
glPushMatrix();
GLfloat light_position[] = {0,50.0,400,1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position); //add in the light
glPopMatrix();
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement