[noob question] Help, my Lights won't move!

Hi all,

I’ve been trying to program a simple example in OpenGL for two days now. I’m drawing a sphere and trying to light it from one side.


//Code example using GLUT
//before the main loop:
glClearColor(0.7f, 0.7f, 0.7f, 0.5f );
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);

//main loop:
void RenderScene(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	if(bLight)
	    glEnable(GL_LIGHT0);
	else glDisable(GL_LIGHT0);
	glLightf(GL_LIGHT0, GL_POSITION,(5.0f,-5.0f,-5.0f,0.0f));
	glPushMatrix();
	glTranslatef(0,0,-200.0f);
	glRotatef(xRot, 1.0f, 0.0f, 0.0f);
	glRotatef(yRot, 0.0f, 1.0f, 0.0f);
	glutSolidSphere(100,10,10);
	glPopMatrix();
	glutSwapBuffers();
}

Whatever I’m putting into the glLightf(…) arguments, the light will not change a bit. Can anyone please tell me why? Am I pushing/popping wrong? Am I supposed to load the identity matrix at some point?

Where is the light currently hitting it? Plus, you need to enable the individual lights AND lighting in general.

glEnable(GL_LIGHTING);

I think that’s a good place to start.

Thank you for the answer.

GL_LIGHTING is enabled, I do that in the initialization phase (even in the example I posted here).

The light is hitting it from the viewpoint (i. e. along the z axis).

If you want lights to move, then you need to place the matrix that you want in the modelview, then call glLight:
GlMatrixmode(modelview)
Glloadmatrix(somematrix)
glLight(gl position)

Another way would be to transform the lights yourself (it’s easy) and call glloadidentity and then glLight.

Also, post programming questions in the beginner forum, please.