PDA

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
glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR, fogColor);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, 8.0f);starts
glFogf(GL_FOG_END, 50.0f);
glFogf(GL_FOG_DENSITY, 2.0f);

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

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

http://i22.photobucket.com/albums/b317/bdeath2/fog_off_1big.jpg
This one shows what happenes if the fog is set off and the light is set to on (from the top)

http://i22.photobucket.com/albums/b317/bdeath2/fog_off_2big.jpg
Same as above, but near the walls

http://i22.photobucket.com/albums/b317/bdeath2/fog_on_big.jpg
This one shows the scene with light and fog turned on.

memfr0b
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.

Thnx