Jump to content
  • Advertisement
Sign in to follow this  
Macerlask

OpenGL OpenGL Lights Positions

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I've a little problem, I'm trying to put a light like a camera flash, so I'm setting the position of the Light just after I loaded the identity matrix in the modelmatrix, like the red book says, but it doesn't work, the light still moving with the object... I'm using GLUT and thise is part of the display callback function code; void DisplayX(void) { GLUquadricObj *MyQuadric; GLfloat lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(20.0f, 1.0f, 1.0f, 10.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); glLightfv(GL_LIGHT0,GL_DIFFUSE,ambientLight); glLightfv(GL_LIGHT0,GL_SPECULAR,specular); glLightfv(GL_LIGHT0,GL_POSITION,lightPos); gluLookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); glMaterialfv(GL_FRONT, GL_SPECULAR,specref); glMateriali(GL_FRONT, GL_SHININESS,128);

Share this post


Link to post
Share on other sites
Advertisement
Sorry, maybe I forgot some details about the programm, in the programm you can rotate a Quadric with the mouse, translate it with the key pads and scalete it with other keys, so when you do all this the transformation should not modificate the position of the light, that's what I´m trying to do...

Share this post


Link to post
Share on other sites
Macerlask, You are mixing up a lot of OpenGL initialisation code with rendering code unecessarily. Take a look at how the NeHe tutorials are structured and see about having things spearated like in the the InitGL() routine, the ResizeGLScene, and a DisplayX() routine. It is of course very much dependent upon your current program setup, but it will help the performance of your program and main render routine if things are separated out.

That being said, try wrapping the remainder of the code for moving the object in a Push and Pop matrix command. ie.

void DisplayX()
{
project matrix setup
light setup
position light
gluLookAt
glPushMatrix();
other translation/rotation code...
glPopMatrix();
glPopMatrix();
other translation/rotation code...
glPopMatrix();
}

hth
F451

Share this post


Link to post
Share on other sites
Thanks for posting, I have solved the problem, the problem was that I was redefining the position of the light every time that it was redered, so what I did was to put the light setup in other funcion and the light position would stay fixed to the camera....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!