I want to add fog in my scene which contain transparent textures made by Blend ,

when i enable the fog the transparent textures appear white From a distance but when i disable it the textures appear well.

What is the solution to the problem of whiteness?

Fog Code:

GLfloat fogColor[4]= {0.5f, 0.5f, 0.5f, 1.0f};
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_DENSITY, 0.35f);
glFogf(GL_FOG_START, 1.0f);
glFogf(GL_FOG_END, 1000.0f);

Screenshot From Opengl

  • \$\begingroup\$ Can you post a screenshot of the problem, and the relevant parts of your code (how you set up blending for your transparent textures, and how you do fog)? \$\endgroup\$ – Nathan Reed May 18 '12 at 17:08
  • \$\begingroup\$ about how i set up blending i'm just write glBlendFunc(GL_SRC_ALPHA,GL_ONE); and before glBegin(GL_QUADS) i'm enabling blend glEnable(GL_BLEND) and after glEnd() i disable it glDisable(GL_BLEND); \$\endgroup\$ – MhdAljobory May 18 '12 at 18:16
  • 1
    \$\begingroup\$ Have you considered getting rid of old OpenGL and switching to shaders? \$\endgroup\$ – Bartek Banachewicz Jun 24 '12 at 9:45

The fog is working as it should work in fixed pipeline. It won't change, because fixed-pipeline support has been dropped.

Today is rendering done with shaders - GLSL.

Fog can be easily implemented in fragment shader:

uniform float fogStart;
uniform float fogEnd;

void main()

    fogFactor = (gl_FragDepth-fogStart)/(fogEnd-fogStart);
    fogFactor = 1 - clamp( fogFactor, 0.0, 1.0 );

    gl_FragColor = vec4(gl_FragColor.xyz, gl_FragColor.w * fogFactor);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.