Open GL Super Bible

Previous Table of Contents Next


Chapter 3
Learning OpenGL With The AUX Library

What you’ll learn in this chapter:


Which headers and libraries are used with OpenGL
How the AUX library provides basic windowing functions on just about any platform
How to use OpenGL to create a window and draw in it
How to use the OpenGL default coordinate system
How to create composite colors using the RGB (red, green, blue) components
How viewports affect image dimensions
How to scale your drawing to fit any size window
How to perform simple animation using double buffering
How to draw predefined objects

Now that you’ve been introduced to OpenGL and the principles of 3D graphics, it’s time to set our hands to writing some OpenGL code. This chapter starts with an overview of how OpenGL works with your compiler, and you’ll learn some conventions for naming variables and functions. If you have already written some OpenGL programs, you may have “discovered” many of these details for yourself. If that is the case, you may just want to skim through the first section and jump right into using the AUX library.

OpenGL: An API, Not a Language

OpenGL is not a programming language; it is an API (Application Programming Interface). Whenever we say that a program is OpenGL-based or an OpenGL application, we mean that it was written in some programming language (such as C or C++) that makes calls to one or more of the OpenGL libraries. We are not saying that the program uses OpenGL exclusively to do drawing. It may combine the best features of two different graphics packages. Or it may use OpenGL for only a few specific tasks, and environment-specific graphics (such as the Windows GDI) for others.

As an API, the OpenGL library follows the C calling convention. This means programs in C can easily call functions in the API either because the functions are themselves written in C or because a set of intermediate C functions is provided that calls functions written in assembler or some other language. In this book, our programs will be written in either C or C++ and designed to run under Windows NT and Windows95. C++ programs can easily access C functions and APIs in the same manner as C, with only some minor considerations. Other programming languages—such as so-called 4GLs (“fourth-generation languages”) like Visual Basic—that can call functions in C libraries can also make use of OpenGL. Chapter 23 discusses this in more detail.


Calling C Functions from C++
Except for the chapters that deal specifically with C++ application frameworks or 4GLs, all of the chapter examples are written in C. On the accompanying CD, many of these samples have also been provided in C++ using two popular application frameworks (MFC and OWL). You can examine these examples and see how we made use of preprocessor macros to keep most of our OpenGL drawing code in C.

The OpenGL Division of Labor

The OpenGL API is divided into three distinct libraries. See Table 3-1 for a breakdown.

  The first, covered in this chapter, is the Auxiliary or AUX library (sometimes referred to as the “toolkit” library), glaux.lib. The declarations for this library are contained in the file glaux.h. The functions contained in this library are not really a part of the OpenGL specification, but rather a toolkit that provides a platform-independent framework for calling OpenGL functions. If your compiler vendor did not supply these files, they can be obtained from the Microsoft Win32 SDK. All functions from this library begin with the prefix aux.
  The functions that actually define OpenGL as specified by the OpenGL Architecture Review Board are contained in the library opengl32.dll, and its header gl.h. Functions from this library are prefixed with gl.
  Finally, there is an OpenGL utility library glu32.dll and its header glu.h. This library contains utility functions that make everyday tasks easier, such as drawing spheres, disks, and cylinders. The utility library is actually written using OpenGL commands, and thus is guaranteed to be available on all platforms that support the OpenGL specification. These functions are all prefixed with glu.

All of the functions in the opengl32.dll and glu32.dll libraries are available for use when using the AUX library for your program’s framework, which is what most of this chapter focuses on. Along the way, you’ll learn the basics of OpenGL, and a few of the commands from the gl library.


Table 3-1 OpenGL libraries and headers
Library Name Library Filename Header File Function Prefix

Auxiliary or Toolkit glaux.lib glaux.h aux
OpenGL or gl opengl32.dll gl.h gl
Utility library or glu glu32.dll glu.h glu


A Note About the Libraries
You may have noticed that the AUX library is actually a library that is linked into your application. The other OpenGL libraries, however, are actually implemented as DLLs. The import libraries that you will need to link to are opengl32.lib and glu32.lib. Typically they are provided by your compiler vendor, or you may obtain them via the Win32 SDK from Microsoft. If you are using Borland C++, you will need to build your own import libraries with Borland’s implib.exe utility.


Previous Table of Contents Next