Problem with fog

I have a problem when i use fog. I think that the fog starts to appear too soon. I use

glFogf (GL_FOG_START, 200000.);
glFogf (GL_FOG_END, 500000.);

so the fog should starts at 200000, but it seems starts at 20 (apox.). I change the value of GL_FOG_START, but there aren’t changes. Anyone can help me? Thanks.

Image

code:

float fog_colour[4] = {0.6f,0.58f,0.79f,0.0f};
float fog_density = 0.03f;

glFogf (GL_FOG_START, 200000.);
glFogf (GL_FOG_END, 500000.);

glFogfv(GL_FOG_COLOR, fog_colour);
glFogf (GL_FOG_DENSITY, fog_density);
glFogi (GL_FOG_MODE, GL_EXP2);

glEnable(GL_FOG);

There may be hardware issues on your platform, often fog is derived from z, especially for per pixel stuff. This can lead to issues with the flexibility of near z and can be worse with exponential modes.

You could try this with linear fog just as a test, but in this case YMMV depending on hardware & maybe driver release version.

Make sure that your problem now is not caused by only having vertex based fog with vertices near the eye & way out there, without a vertex in the middle distance.

Conversely if this is a pixel fog issue per vertex fog may work better for you if you have a reasonable vertex count

glFogi (GL_FOG_MODE, GL_EXP2);

Exponential fog always start at 0. GL_FOG_START and GL_FOG_END are for GL_LINEAR fog only.
If you need exponential fog starting from different point than 0 then you will have to use shader, or create a 1-D texture with predefined fog values for different distances and map it to your scene using tex gen.

If i use GL_LINEAR then the fog works well. So,
i’ll do with this mode.

A lot of thanks!!