JMU
Fog in OpenGL


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Motivation
Fog Equations
Using Fog in OpenGL
An Example

Initialization

openglexamples/fog/fog.c (Fragment: initFog)
          glEnable(GL_FOG);
  {
    glFogi(GL_FOG_MODE, GL_EXP);
    glFogfv(GL_FOG_COLOR, colorGray);
    glFogf(GL_FOG_DENSITY, 0.45);
  }
  glClearColor(colorGray[0], colorGray[1], colorGray[2], colorGray[3]);
        
An Example (cont.)

Rendering

openglexamples/fog/fog.c (Fragment: display)
        /**
 * Display/render the OpenGL window
 */
void display() {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix();
  glTranslatef(-1.0, -0.5, -2.0);
  glutSolidTeapot(0.5f);
  glPopMatrix();

  glPushMatrix();
  glTranslatef(0.0, -0.5, -3.5);
  glutSolidTeapot(0.5f);
  glPopMatrix();

  glPushMatrix();
  glTranslatef(1.0, -0.5, -5.0);
  glutSolidTeapot(0.5f);
  glPopMatrix();

  glFlush();
}