Porting Depth Cueing and Fog Commands

When porting depth-cueing and fog commands, keep the following points in mind:

  • The IRIS GL call, fogvertex, sets a mode and the parameters affecting that mode. In OpenGL, you call glFog once to set the mode, and then again twice or more to set various parameters.

  • In OpenGL, depth cueing is not a separate feature. Use linear fog instead of depth cueing. (This section gives an example of how to do this.) The following IRIS GL functions have no direct OpenGL equivalent:

    depthcue

    lRGBrange

    lshaderange

    getdcm

  • To adjust fog quality, use glHint( GL_FOG_HINT ).

The following table lists the IRIS GL functions for managing fog and their equivalent OpenGL functions.

IRIS GL function OpenGL function Meaning
fogvertex glFog Sets various fog parameters.
fogvertex( FG_ON ) glEnable ( GL_FOG ) Turns on fog.
fogvertex( FG_OFF ) glDisable ( GL_FOG ) Turns off fog.
depthcue glFog ( GL_FOG_MOD, GL_LINEAR ) Uses linear fog for depth cueing.

The following table lists the parameters you can pass to glFog.

Fog parameter Meaning Default
GL_FOG_DENSITY Fog density. 1.0
GL_FOG_START Near distance for linear fog. 0.0
GL_FOG_END Far distance for linear fog. 1.0
GL_FOG_INDEX Fog color index. 0.0
GL_FOG_COLOR Fog RGBA color. (0, 0, 0, 0)
GL_FOG_MODE Fog mode. See the following table.

The fog-density parameter of OpenGL differs from the one in IRIS GL. They are related as follows:

  • if fogMode = EXP2

    openGLfogDensity = (irisGLfogDensity ) ( sqrt ( log ( 1 / 255 ) ))

  • if fogMode = EXP

    openGLfogDensity = (irisGLfogDensity ) ( log ( 1 / 255 ) )

where sqrt is the square root operation, log is the natural logarithm, irisGLfogDensity is the IRIS GL fog density, and openGLfogDensity is the OpenGL fog density.

To switch between calculating fog in per-pixel mode and per-vertex mode, use glHint( GL_FOG_HINT, hintMode). Two hint modes are available:

  • GL_NICEST per-pixel fog calculation
  • GL_FASTEST per-vertex fog calculation

The following table lists the IRIS GL fog modes and their OpenGL equivalents.

IRIS GL fog mode OpenGL fog mode Hint mode Meaning
FG_VTX_EXP,FG_PIX_EXP
GL_EXP GL_FASTEST,GL_NICEST
Heavy fog mode (default).
FG_VTX_EXP2,FG_PIX_EXP2
GL_EXP2 GL_FASTEST,GL_NICEST
Haze mode.
FG_VTX_LIN,FG_PIX_LIN
GL_LINEAR GL_FASTEST,GL_NICEST
Linear fog mode. (Use for depth cueing.)

The following code example demonstrates depth cueing in OpenGL:

/* 
 *  depthcue.c 
 *  This program draws a wire frame model, which uses 
 *  intensity (brightness) to give clues to distance 
 *  Fog is used to achieve this effect 
 */ 
#include <GL/gl.h> 
#include <GL/glu.h> 
#include "aux.h" 
 
/*  Initialize linear fog for depth cueing 
 */ 
void myinit(void) 
{ 
    GLfloat fogColor[4] = {0.0, 0.0, 0.0, 1.0}; 
 
    glEnable(GL_FOG); 
    glFogi (GL_FOG_MODE, GL_LINEAR); 
    glHint (GL_FOG_HINT, GL_NICEST);  /*  per pixel  */ 
    glFogf (GL_FOG_START, 3.0); 
    glFogf (GL_FOG_END, 5.0); 
    glFogfv (GL_FOG_COLOR, fogColor); 
    glClearColor(0.0, 0.0, 0.0, 1.0); 
 
    glDepthFunc(GL_LEQUAL); 
    glEnable(GL_DEPTH_TEST); 
    glShadeModel(GL_FLAT); 
} 
 
/*  display() draws an icosahedron 
 */ 
void display(void) 
{ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glColor3f (1.0, 1.0, 1.0); 
    auxWireIcosahedron(1.0); 
    glFlush(); 
} 
 
void myReshape(GLsizei w, GLsizei h) 
{ 
    glViewport(0, 0, w, h); 
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    gluPerspective (45.0, (GLfloat) w/(GLfloat) h, 3.0, 5.0); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity (); 
    glTranslatef (0.0, 0.0, -4.0); /*move object into view*/ 
} 
/*  Main Loop 
 */ 
int main(int argc, char** argv) 
{ 
    auxInitDisplayMode (AUX_SINGLE | AUX_RGBA | AUX_DEPTH); 
    auxInitPosition (0, 0, 400, 400); 
    auxInitWindow (argv[0]); 
    myinit(); 
    auxReshapeFunc (myReshape); 
    auxMainLoop(display); 
}