View Full Version : Lighting without the fog...

Black Death
10-21-2005, 02:52 AM
I'm working on a simple engine and recently i found this problem... The whole scene is lit dark (almost black) if the fog is off, and the light(s) is on. If I move near the objects, the objects become brighter. Here is the code i use for ligting...

// fog and light colors
float fogColor[3] = { 0.5f, 0.0f, 0.788f };
float Position[4] = { 0.0f, 10.0f, 15.0f, 0.0f };
float Ambient[4] = { 0.5f, 0.0f, 1.0f, 1.0f };
float Diffuse[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
// in the initialize function
// fog setup
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_START, 8.0f);starts
glFogf(GL_FOG_END, 50.0f);
glFogf(GL_FOG_DENSITY, 2.0f);

// light0 setup
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);

// enable color tracking
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);Anyone knows what's wrong?
here are some screenshots

This one shows what happenes if the fog is set off and the light is set to on (from the top)

Same as above, but near the walls

This one shows the scene with light and fog turned on.

10-22-2005, 04:45 AM
Your objects become darker, the farther you get away from them, because your the light source moves with the camera. The light's position is stored in view space, so until you set the position again, it stays at a fixed position, relative to the camera.

If you want your light to stay at a fixed position, relative to "the world", you have to set the light position every frame after you apply your view transformation (ie gluLookAt).

Black Death
10-23-2005, 03:57 AM
That worked :D
Now I call glLightfv(GL_LIGHT0, GL_POSITION, pos) after gluLookAt() and it works perfectly.