Generic Notes on OpenGL Games Programming

Sections

Phong Shading

Vertex Blending / Skinning

Polygon Smoothing and Stippling

Double and Triple Buffering

Polygon Offset

Alpha Testing / Chroma Keying

Clipping

Fog

Specular Highlights on Textures

Phong Shading

Actual phong shading of a primitive (as opposed to Gouraud or flat shading) is described as "per fragment" shading in OpenGL. The appropriate extension is EXT_fragment_lighting, but as of December 1999 it is not implemented on any Windows consumer board that I know of.

Vertex Blending / Skinning

This can be done using the EXT_vertex_weighting extension.

Polygon smoothing and stippling

As of December 1999, available hardware drivers vary in their treatment of glEnable(GL_POLYGON_SMOOTH) and glEnable(GL_LINE_SMOOTH) calls. Some appear to ignore it completely; others (correctly, if they cannot implement it in hardware) default to software rendering. This is a common cause of unexpected frame rate crashes on hardware you don't test on regularly.

You may also experience similar (but much less widespread) issues with support for glEnable(GL_LINE_STIPPLE) and glEnable(GL_POLYGON_STIPPLE).

Double and Triple Buffering

OpenGL implementations can be double or triple buffered, and the swap can occur via blitting or hardware frame swaps. The interface specifies only that the contents of the current draw buffer be swapped into the visible buffer when SwapBuffers is called. There is no guarantee that anything in particular will be left in the back buffer, and it is unwise to assume that the back buffer will contain the front buffer image after a swap on all drivers.

Polygon Offset

glPolygonOffset can be used in OpenGL 1.1 and later to ensure that geometry rendered coplanar with existing geometry is not obscured by it, without disabling the depth buffer or using stencils. Note that the semantics of the 1.1 version (unlike the 1.0 extension) allow drivers to export an interface which is not dependent on the characteristics of the underlying hardware; if an implementation has unusual OpenGL 1.1 polygon offset characteristics, that can be treated as a bug.

Typical parameter values for glPolygonOffset for rendering coplanar geometry such as shadows or wall marks are -1.0f for both the factor and the units.

Alpha Testing / Chroma Keying

OpenGL does not support the "chroma key" (a selected colour is not rendered) approach to making textures (e.g. sprites) partially transparent, since it raises awkward issues in the interface definition (e.g. what should be done with a chroma key colour during mip map generation?). The same effect can be achieved by providing a texture map with at least one bit of alpha and using the GL_ALPHA_TEST pathway. Note that on almost all Win32 consumer hardware, texture maps with more than one bit of alpha can have their alpha information bilinearly filtered before the alpha test is done, which can be helpful when rendering sprites close to the camera.

Clipping

Screen space clipping is automatically performed by an OpenGL implementation, and is normally extremely fast. If you are interested in optimising frame rate by reducing the clipping operations done in the driver, you may want to look at the clip volume extension.

Fog

For the sake of greater speed, fog in OpenGL is normally calculated using the z distance in eye space, which may produce artifacts e.g. under rotation. If this is an issue, you may want to investigate the fog_coord extension.

Specular Highlights on Textures

If you want to do this and you have a 1.1 rather than a 1.2 core implementation, you may want to use the EXT_separate_specular_color and EXT_secondary_color extensions.

Back to main