Lights

I got this weird feature in my engine right now. I draw my scene, but the light isn’t smooth and doesn’t seem to rotate with the screen. Should I rotate and set the light every frame ?

–> Divide Overflow

Yep sir !

Just for information, here is the start of my RenderScene() code :

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
SetupViewingFrustum(m_WindowWidth,m_WindowHeight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
SetEyePosition();
SetLights();

Then, after some glEnable/glDisable, I call a display list…

As you can see, the lights are positioned every frame, after having set the eye position with gluLookAt…

Regards.

Eric

The light position is handled like a vertex and fed through the modelview matrix.
Means, if you specify the light’s position outside of your transformation stage it will be multiplied by the default modelview matrix which is identity and ends up not moving with the world.
So the above code transforms the light with the rest of the geometry.
You don’t have to specify all the light parameters again except for the postion.

Thanx guys, it fixed one thing

But now, weird, I can get a multitextured lightmap to work, but a simple light is a pain in the *ss

Anyway, I got my lights loaded with lotts o’ stuph :

glLightf(GL_LIGHT0,L_CONSTANT_ATTENUATION, 0.0);
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.4);
glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION, 0.0);
glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);

and the lights are set every frame by

LightAmbient[0] = (float)this->Ambient.r;
LightAmbient[1] = (float)this->Ambient.g;
LightAmbient[2] = (float)this->Ambient.b;
LightAmbient[3] = (float)this->Ambient.a;
LightDiffuse[0] = (float)this->Diffuse.r;
LightDiffuse[1] = (float)this->Diffuse.g;
LightDiffuse[2] = (float)this->Diffuse.b;
LightDiffuse[3] = (float)this->Diffuse.a;
LightPosition[0] = (float)this->Position.x;
LightPosition[1] = (float)this->Position.y;
LightPosition[2] = (float)this->Position.z;
LightPosition[3] = (float)this->Strength;

glLightf(GL_LIGHT0 + index, GL_CONSTANT_ATTENUATION, 0.0);

{
glLightf(GL_LIGHT0+index, GL_LINEAR_ATTENUATION, 0.0);
glLightf(GL_LIGHT0+index, GL_QUADRATIC_ATTENUATION, 0.1);
}
glEnable(GL_LIGHT0+index);
glLightfv(GL_LIGHT0+index, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0+index, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT0+index, GL_POSITION,LightPosition);

However… I seem to get one hell of a big block of light at the left of my scene when I set my light up like this :

	Light->Position.x = 0;
	Light->Position.y = 1;
	Light->Position.z = 0;
    Light->Ambient.a = 0.0f;
    Light->Ambient.r = 0.0f;
    Light->Ambient.g = 0.0f;
    Light->Ambient.b = 0.0f;
	Light->Diffuse.a = 1.0f;
  Light->Diffuse.r = 1.0f;
  Light->Diffuse.g = 1.0f;
	Light->Diffuse.b = 1.0f;
    Light->Strength = 0.0f;
    Light->SetLight(0);

Suggestions ?