PDA

View Full Version : Fog not relative to camera position



shouwel
05-29-2013, 04:26 AM
Hi all,
I've been stuck for a few hours with the following problem: the fog does not move with the camera. Often this problem seems to be caused by using glTranslate/glRotate with the PROJECTION_VIEW matrix, but I don't think this is the case here. Is there anyone willing to go over the pieces of code below and maybe help me? My scene is a straight hallway through which the camera moves forward at slowly varying speeds and the fog should keep the same distance from the camera (which is what it is by default supposed to do, right?). Instead, the camera moves through the fog after a certain distance. I tried to fix it by adjusting GL_FOG_START and GL_FOG_END with the distance translated: this keeps the fog more steady, but still the distance between camera and fog is not constant. (ps: I am a researcher with some programming experience, writing my own code for experimental purposes, not game development...)

init(){
[...]
float FogCol[3]={0.8f,0.8f,0.8f};
glFogfv(GL_FOG_COLOR,FogCol);
glFogf(GL_FOG_DENSITY, 1.f);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_START, 4000);
glFogf(GL_FOG_END, 5000);
[...]
}

reshape(){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat facZ = 1;
glFrustum(facZ*-0.0083,facZ*0.0083,facZ*-0.00719,facZ*0.00240,facZ*0.01,6000);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,-REL_EYE_HEIGHT,200.0);
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
}

display(){
if (frame > DURATION){
return;
}
frame = frame + 1;
glutPostRedisplay();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_FOG);

glPushMatrix();
glTranslatef(0.0,0.0,fwd_translation[frame]);

[scene drawing]

glPopMatrix();
glutSwapBuffers();
glFlush();


}

shouwel
06-03-2013, 02:17 AM
Please? Anyone?