OpenGL (1.2 - 2.0) Code Samples - Page 5

Polygon Offset
 

This sample demonstrates how to eliminate z-fighting when rendering polygons directly on top of other polygons  by using glPolygonOffset and GL_POLYGON_OFFSET_FILL.

Relevant Keywords: glPolygonOffset glEnable, glDisable, GL_POLYGON_OFFSET_POINT, GL_POLYGON_OFFSET_LINE, and GL_POLYGON_OFFSET_FILL.

 

First Person Shooter Controls
 

Demonstrates how to manually modify the view matrix using mouse and keyboard input to create a First Person Shooter style control. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: glMatrixMode, glMultMatrixf, glLoadIdentity, glColor3f, glutWireTeapot, glInterleavedArrays, GL_PROJECTION, GL_MODELVIEW, GL_C4UB_V3F, and GL_LINES.

 

Lighting
 

This sample demonstrates the three basic types of lights that are available in OpenGL: directional, spot, and point. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: glLightfv, glLightf, glMaterialfv, glLightModelfv, glEnable, glDisable, glPushAttrib, glPopAttrib, gluLookAt, glPushMatrix, glPopMatrix, glTranslatef, glRotatef, glutSolidCone, glutSolidSphere, GL_LIGHTING, GL_FRONT, GL_DIFFUSE, GL_AMBIENT, GL_POSITION, GL_SPOT_DIRECTION, GL_CONSTANT_ATTENUATION, GL_SPOT_CUTOFF, GL_SPOT_EXPONENT, GL_LINEAR_ATTENUATION, GL_LIGHT0, GL_LIGHT1, GL_LIGHT_MODEL_AMBIENT, GL_LIGHTING_BIT, GL_TRIANGLES, GL_MODELVIEW_MATRIX, and GL_N3F_V3F.

 

Materials
 

Demonstrates how to use materials with lighting to produce different surface effects. Check out the DirectX9 source code page for the Direct3D equivalent of this sample.

Relevant Keywords: glMaterialfv, glLightModelfv, glLightfv, glEnable, GL_COLOR_MATERIAL, GL_FRONT_AND_BACK, GL_DIFFUSE, GL_AMBIENT, GL_EMISSION, GL_SPECULAR, GL_SHININESS, and GL_POSITION.

Color Tracking and Two-Sided lighting
 

This sample demonstrates color-tracking and two-sided lighting in OpenGL.

Color tracking allows us to substitute the color of our vertices for one or more of the material colors used by OpenGl's lighting equation. This feature is typically not used much anymore since modelers today use textures to color their geometry - not vertex colors. Of course, this technique is alive and kicking in a billion lines of legacy code so it's good to understand this technique just in case you run across it.

Two-sided lighting basically means that we want OpenGL to
light both sides of our geometry instead of just the front faces. Again, this feature is typically not used much anymore since it's very inefficient to light both sides of every triangle but there are some cases where this is helpful to know.

Relevant Keywords: glColorMaterial, glLightModeli, glMaterialfv, glLightModelfv, glLightfv, glEnable, GL_LIGHT_MODEL_TWO_SIDE, GL_COLOR_MATERIAL, GL_FRONT_AND_BACK, GL_FRONT, GL_BACK, GL_DIFFUSE, GL_AMBIENT, GL_EMISSION, GL_SPECULAR, GL_SHININESS, and GL_POSITION.