OpenGL Lights Positions
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);
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...
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement