This article is brought to you by Premier Press|
publisher of Kevin Hawkins' and Davide Astle's OpenGL Game Programming.
OpenGL provides the programmer with an interface to graphics hardware. It is a powerful, low-level rendering and modeling software library, available on all major platforms, with wide hardware support. It is designed for use in any graphics applications, from games to modeling to CAD. Many games, such as id Software's Quake 3, shown in Figure 1, use OpenGL for their core graphics-rendering engines.
Quake 3 Arena
OpenGL was originally developed by Silicon Graphics, Inc. (SGI) as a multi-purpose, platform-independent graphics API. Since 1992, the development of OpenGL has been overseen by the OpenGL Architecture Review Board (ARB), which is made up of major graphics vendors and other industry leaders, currently consisting of ATI, Compaq, Evans & Sutherland, Hewlett-Packard, IBM, Intel, Intergraph, nVidia, Microsoft, and Silicon Graphics. The role of the ARB is to establish and maintain the OpenGL specification, which dictates which features must be included when one is developing an OpenGL distribution.
At the time of this writing, the most recent version of OpenGL is Version 1.2. OpenGL has been around for a while, so the fact that it's only at version 1.2 should suggest something: The specification doesn't get updated that often.
Because OpenGL is designed to be used with high-end graphics workstations, it has, until recently, included the power to take full advantage of consumer-level graphics hardware. Furious competition over the last couple of years, however, has brought features once available only on graphics workstations to the consumer level; as a result, there are more and more video cards of which OpenGL can't take full advantage. Fortunately, the video-card manufacturers can and do provide OpenGL extensions, which allow you to access advanced hardware-specific features. Eventually, these extensions may become official additions to the OpenGL standard. OpenGL 1.2 was the first version to contain support for features specifically requested by game developers (such as multitexturing), and it is likely that future releases will be influenced by gaming as well.
OpenGL is a collection of several hundred functions providing access to all the features offered by your graphics hardware. Internally, it acts as a state machine--a collection of states that tell OpenGL what to do. Using the API, you can set various aspects of the state machine, including such things as the current color, lighting, blending, and so on. When rendering, everything drawn is affected by the current settings of the state machine. It's important to be aware of what the various states are, and the effect they have, because it's not uncommon to have unexpected results due to having one or more states set incorrectly.
At the core of OpenGL is the rendering pipeline, as shown in Figure 2. You don't need to understand everything that happens in the pipeline at this point, but you should at least be aware that what you see on the screen results from a series of steps. Fortunately, OpenGL handles most of these steps for you.
The OpenGL rendering pipeline.
Under Windows, OpenGL provides an alternative to using the Graphics Device Interface (GDI). GDI architects designed it to make the graphics hardware entirely invisible to Windows programmers. This provides layers of abstraction that help programmers avoid dealing with device-specific issues. However, GDI is intended for use with applications and thus lacks the speed required for games. OpenGL allows you to bypass GDI entirely and deal directly with graphics hardware. Figure 3 illustrates the OpenGL hierarchy under Windows.
OpenGL API hierarchy under Windows systems.
The OpenGL Utility Library
The OpenGL Utility Library, or GLU, supplements OpenGL by providing higher-level functions. GLU offers features that range from simple wrappers around OpenGL functions to complex components supporting advanced rendering techniques. Its features include:
- 2D image scaling
- Rendering 3D objects including spheres, cylinders, and disks
- Automatic mipmap generation from a single image
- Support for curves surfaces through NURBS
- Support for tessellation of non-convex polygons
- Special-purpose transformations and matrices
What Is GLUT?
GLUT, short for OpenGL Utility Toolkit, is a set of support libraries available on every major platform. OpenGL does not directly support any form of windowing, menus, or input. That's where GLUT comes in. It provides basic functionality in all of those areas, while remaining platform independent, so that you can easily move GLUT-based applications from, for example, Windows to UNIX with few, if any, changes.
GLUT is easy to use and learn, and although it does not provide you with all the functionality the operating system offers, it works quite well for demos and simple applications.
Because your ultimate goal is going to be to create a fairly complex game, you're going to need more flexibility than GLUT offers; however, if you'd like to know more, visit the official GLUT Web page at http://reality.sgi.com/mjk/glut3/.
A Sneak Peek
Let's take a look at some code that you can use. The example shown in Figure 4 shows a rotating, lit, texture-mapped cube reflecting on a surface. The code for this example program can be found with our book. Although much of it might not make sense to you, it will at least give you an idea of what you can do. Also, note that this code uses GLUT for handling all the operating system-specific stuff. If you decide to build this example on your own, be sure to copy the GLUT headers and libraries to your compiler's directory, just as you did with the OpenGL headers and libraries.
A simple OpenGL example program
In our next article, we will cover DirectX and its importance to game developers.
About the Authors
Kevin Hawkins is is the CEO of GameDev.net, a development sites on the web for game programmers.
Dave Astle is the COO of GameDev.net where he acts as the chairman and editor-in-chief. He is founder of Myopic Rhino games and is currently a software engineer in Salt Lake City, Utah.
Andre LaMothe is the CEO of Xtreme Games LLC and series editor for the Premier Press game development book series. He has worked in 2D/3D graphics, artificial intelligence at NASA, compiler design, robotics engineering, virtual reality, telecommunications, and has been a consultant to various companies located in Silicon Valley. Andre' is also the inventor of one of the world's first commercially available virtual reality games, CyberCafe, created in the early '90s.
This article is brought to you by Premier Press
publisher of OpenGL Game Programming
) Copyright Prima Publishing, All Rights Reserved