Question

This is how I enable fog in OpenGL:

float fog_colour[4] = {1,1,1,1};
glEnable(GL_FOG);
glFogf(GL_FOG_MODE,GL_EXP2);
glFogfv(GL_FOG_COLOR,fog_colour);
glFogf(GL_FOG_DENSITY,0.5);
glHint(GL_FOG_HINT,GL_NICEST);
glFogf(GL_FOG_START,0.1);
glFogf(GL_FOG_END,100);

Every object is in the range 0.1-100, but fog just doesn't appear, what happened?

Was it helpful?

Solution

The problem is the GL_EXP2 mode.

If you check the formula for the fog blending factor in GL_EXP2 mode:

f = e ^ ((-density * z) ^2) (clamped to [0..1])

The fog curve is adjusted exclusively with the density parameter. If your range is 0.1-100, I would recommend a density of about 0.001.

Anyway, for testing fog is better to begin first with a GL_LINEAR mode. It's just easier to visualize.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top