fog not respecting depth?


I’ve decided to add fog to my rendering engine. After I setup and enable fog however, the scene is fogged a constant amount irrespective of the depth (ie, objects at the near clip plane are fogged just as much as objects at the far clip plane). I set up fogging as shown in the GL red book, like so:

// gl is a struct I have to hod my GL globals
gl->fog_start= 0.f;
gl->fog_end= 10000.f; // far clip plane distance
gl->fog_density= 0.35f;
gl->fog_color.r= 0.f;
gl->fog_color.g= .5f; // make fog green so it’s easy for me to see
gl->fog_color.b= 0.f;
gl->fog_color.a= 1.f;

glFogf(GL_FOG_DENSITY, gl->fog_density);
glFogf(GL_FOG_START, gl->fog_start);
glFogf(GL_FOG_END, gl->fog_end);
glFogfv(GL_FOG_COLOR, (float *)&gl->fog_color);

glClearColor(gl->fog_color.r, gl->fog_color.g, gl->fog_color.b, gl->fog_color.a);

Does anyone have any ideas what might cause OpenGL to behave in this fashion? Any help is greatly appreciated!

FOG_START and FOG_END do not apply to EXP or EXP2 fog, only to linear fog.

You probably have full fog at the distance you’re rendering. EXP2 goes up quickly.

Watch out, the fog calculation is working from the origin. Don’t translate the projecttion matrix.

That was my typo there… I am actually using linear fog, but thanks for the tip; I realized what I was doing wrong - I was modifying the projection matrix elsewhere when I should not have been :stuck_out_tongue: I am learning, slowly but surely… heheh