PDA

View Full Version : Fog problems



paddy
10-17-2000, 02:21 AM
I use this code to enable fog :

glFloat col[4];
col[0]=...
col[1]=...
col[2]=...
col[3]=...

glFogf(GL_FOG_MODE,GL_EXP);
glFogf(GL_FOG_DENSITY,0.02);
glFogf(GL_FOG_START,1.0);
glFogf(GL_FOG_END,5.0);
glHint(GL_FOG_HINT,GL_NICEST);
glFogfv(GL_FOG_COLOR,col);
glEnable(GL_FOG);

The fog generated don't rotate with my scene.
When i rotate the camera, the fog is thick on the z axis, but becomes thinner when i rotate the camera away from the z axis.
(mmmhhh... i hope the explanation is clear)
Do anyone have a solution ?

Bob
10-17-2000, 02:45 AM
Well, then explanation was a tad thin, but I can try to come up with a reason. I think you are doing the transformations (glTranslate/glRotate) in the projection matrix and not the modelview matrix.

Well, what does the matrices got to do with fog you might ask. Fog is applied before the projection matrix, but after the modelview matrix. If you do translations in the projection matrix, the fog engine will recieve untransformed coordinates, and therefore might screw up fogging.

And another tip: No need to pass start and end coordinates if you use GL_EXP or GL_EXP2 fog. Nor is it necessary to pass a fog density when using linear fog.

paddy
10-17-2000, 03:51 AM
Thanks Bob, this works fine now http://www.opengl.org/discussion_boards/ubb/biggrin.gif