Porting Depth Cueing and Fog Commands

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

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

IRIS GL Function OpenGL Function Meaning
fogvertex glFog Set various fog parameters.
fogvertex(FG_ON) glEnable(GL_FOG) Turn fog on.
fogvertex(FG_OFF) glDisable(GL_FOG) Turn fog off.
depthcue glFog(GL_FOG_MOD, GL_LINEAR) Use 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:

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:

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