Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Fog not relative to camera position

  1. #1
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    4

    Fog not relative to camera position

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


    }
    Last edited by shouwel; 05-29-2013 at 05:13 AM. Reason: I am a little uncertain whether the question is clear, because of the19 views and 0 reply

  2. #2
    Junior Member Newbie
    Join Date
    May 2013
    Posts
    4
    Please? Anyone?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •