Creating Real Time 3D Graphics With OpenGL
Pages: 1, 2, 3

What exactly is OpenGL?

OpenGL is an API to assist in delivering 3D drawing services in real-time environments. It's an immediate mode design, in that each frame is drawn explicitly by the client application, and each mode change will affect all subsequent drawing calls. This is instead of a retained mode design (like SGI's IRIX Performer), where the client application first describes the scene and then changes the camera and objects as needed.

The OpenGL API itself is controlled by an independent board, known as the Architecture Review Board (ARB), with each member having a single vote. The ARB governs changes and extensions to the API, new releases, and the conformance tests. This ensures that SGI can't solely control where the standard goes. News and development information is available at the site.

It's interesting to note that through its extension functions, new abilities are added to OpenGL in a very open-source manner. Any implementer can add a new extension, so long as it includes a prefix which identifies it as unique to the implementer. If the extension is submitted to the ARB and approved for adoption, it then becomes part of the official standard.

Figure 2. The classic teapot example to help developers with shape design.

The classic teapot object to help developers with lighting and texture design

The API is carefully designed to allow large portions of the work to be carried out with the assistance of 3D hardware. A full implementation (like OpenGL or Mesa, but unlike many of the MiniGLs) will fall back from hardware acceleration to a software version for any features requested that aren't available from the hardware. This is referred to as falling back from the fast path to a slow path and can dramatically lower the frame rate delivered.

Rendering, or drawing, complex and realistic scenes full-screen at 50 frames per second is not possible even with today's fastest general-purpose processors, so specialized hardware assistance is needed for most applications. Small demonstration programs can still be run solely with software rendering, for example, as can applications where high frame rates aren't needed. But once hardware acceleration is used, no one is ever willing to go back.

To the application program author, OpenGL provides approximately 250 calls, or entry points, that are used to set up the rendering environment, create lights, and set background colors, drawing and blending modes, etc. Calls are also provided for drawing points, lines, polygons (convex and planar only, please), and bitmaps. These can be painted with textures and "lit" in different ways.

OpenGL provides several different types of buffers that the programmer can use to render the scene. For example, the frame or color buffer is where the actual drawing that is seen by the user takes place. There may be several frame buffers available, including front and back versions of both left and right buffers. Each OpenGL implementation can offer all of these, plus additional auxiliary buffers, or may only provide a subset. At the minimum, at least one frame buffer must be available.

Other buffer types include a depth or Z buffer, which is used to eliminate hidden surfaces, and a stencil buffer, used to control where drawing takes place. Lastly, an accumulation buffer can be used to blend scenes together for motion blur and anti-aliasing effects. Not all buffers are supported in hardware on all devices though, and using an unsupported buffer will slow the refresh rate down considerably.

There are also several support libraries available for use with OpenGL, two of the most important being the OpenGL Utility (GLU) library and the OpenGL Utility Toolkit (GLUT). The former provides functions that help in creating texture mipmaps (explained below), accessing extended functions of OpenGL, as well as several that assist in building different object types including complex, curved NURBs and quadratic surfaces.

The latter library, GLUT, was written by Mark Kilgard, and is a windowing-system-independent toolkit designed to let a program run anywhere, regardless of the platform. In addition to window creation, handling, and event-processing functions, the library also provides several object creation functions. Included are wire and solid versions of a sphere, cube, torus, and cone, plus icosa-, octa-, tetra- and dodeca-hedrons. And, just for fun, a teapot is available at the request of a single function call.

3D programming is quite math intensive, relying on passing objects through 4x4 floating point transform matrices in order to figure out how a bunch of rotated, transformed, scaled objects map to a rotated, transformed, scaled projection. While those strong in math are welcome to manipulate the various matrices directly, those to whom math is rather intimidating can still produce impressive results using OpenGL and nothing but the simplest trigonometry.

Pages: 1, 2, 3

Next Pagearrow