// Set red fog some where
GLfloat red[4] = {1,0,0,0};
glFogfv (GL_FOG_COLOR, red);
…
// Here set black fog
GLfloat black[4] = {0,0,0,0};
glFogfv (GL_FOG_COLOR, black);
glDrawElements(… …);
This produces black fogged scene, as we expected.
now, I change the code to:
// Set red fog some where
GLfloat red[4] = {1,0,0,0};
glFogfv (GL_FOG_COLOR, red);
…
// Here set black fog
glPushAttrib (GL_FOG_BIT); // Added
GLfloat black[4] = {0,0,0,0};
glFogfv (GL_FOG_COLOR, black);
glDrawElements(… …);
glPopAttrib (GL_FOG_BIT); // Added
Now the scene is rendered with red fog! Why? It’s quite strange, and it happens with both ATI X700 and NVidia FX5200.
Try a glFlush/glFinish (?) just before the glPopAttrib. I wouldn’t think this would/should make a difference but that’s the only thing I can see that might be a problem.
Do you use shaders or fixed function pipeline? Some drivers were not correctly updating the fog parameters inside the shaders until next time the shader was bound.
I have seen such an effect. When you don’t render anything yet, calls to glFogfv(GL_FOG_COLOR, …) work, but it seems as if after, they are ignored. I have this one project that does it and it still doesn’t work now that I tried it. Radeon 9700 with Cat 6.7