Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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};
glClearColor(0.5f,0.5f,0.5f,1.0f);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogfv(GL_FOG_COLOR, fogColor);
glFogf(GL_FOG_DENSITY, 0.35f);
glHint(GL_FOG_HINT, GL_DONT_CARE);
glFogf(GL_FOG_START, 1.0f);
glFogf(GL_FOG_END, 1000.0f);
glEnable(GL_FOG);

Screenshot From Opengl

share|improve this question
    
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)? –  Nathan Reed May 18 '12 at 17:08
    
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); –  MhdAljobory May 18 '12 at 18:16
1  
Have you considered getting rid of old OpenGL and switching to shaders? –  Bartek Banachewicz Jun 24 '12 at 9:45
add comment

1 Answer

up vote 3 down vote accepted

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);

}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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