Table of Contents
1. Contents
About This Guide
What This Guide Contains
What's New in This Edition
What You Should Know Before Reading This Guide
How to Obtain the Sample Code
Nate Robins' OpenGL Tutors
Errata
Style Conventions
-Acknowledgments
-Figures
-Tables
-Examples
1. Introduction to OpenGL
What Is OpenGL?
A Smidgen of OpenGL Code
OpenGL Command Syntax
OpenGL as a State Machine
OpenGL Rendering Pipeline
Display Lists
Evaluators
Per-Vertex Operations
Primitive Assembly
Pixel Operations
Texture Assembly
Rasterization
Fragment Operations
OpenGL-Related Libraries
Include Files
GLUT, the OpenGL Utility Toolkit
Animation
The Refresh That Pauses
Motion = Redraw + Swap
2. State Management and Drawing Geometric Objects
A Drawing Survival Kit
Clearing the Window
Specifying a Color
Forcing Completion of Drawing
Coordinate System Survival Kit
Describing Points, Lines, and Polygons
What Are Points, Lines, and Polygons?
Specifying Vertices
OpenGL Geometric Drawing Primitives
Basic State Management
Displaying Points, Lines, and Polygons
Point Details
Line Details
Polygon Details
Normal Vectors
Vertex Arrays
Step 1: Enabling Arrays
Step 2: Specifying Data for the Arrays
Step 3: Dereferencing and Rendering
Interleaved Arrays
Attribute Groups
Some Hints for Building Polygonal Models of Surfaces
An Example: Building an Icosahedron
3. Viewing
Overview: The Camera Analogy
A Simple Example: Drawing a Cube
General-Purpose Transformation Commands
Viewing and Modeling Transformations
Thinking about Transformations
Modeling Transformations
Viewing Transformations
Projection Transformations
Perspective Projection
Orthographic Projection
Viewing Volume Clipping
Viewport Transformation
Defining the Viewport
The Transformed Depth Coordinate
Troubleshooting Transformations
Manipulating the Matrix Stacks
The Modelview Matrix Stack
The Projection Matrix Stack
Additional Clipping Planes
Examples of Composing Several Transformations
Building a Solar System
Building an Articulated Robot Arm
Reversing or Mimicking Transformations
4. Color
Color Perception
Computer Color
RGBA versus Color-Index Mode
RGBA Display Mode
Color-Index Display Mode
Choosing between RGBA and Color-Index Mode
Changing between Display Modes
Specifying a Color and a Shading Model
Specifying a Color in RGBA Mode
Specifying a Color in Color-Index Mode
Specifying a Shading Model
5. Lighting
A Hidden-Surface Removal Survival Kit
Real-World and OpenGL Lighting
Ambient, Diffuse, Specular, and Emissive Light
Material Colors
RGB Values for Lights and Materials
A Simple Example: Rendering a Lit Sphere
Creating Light Sources
Color
Position and Attenuation
Spotlights
Multiple Lights
Controlling a Light's Position and Direction
Selecting a Lighting Model
Global Ambient Light
Local or Infinite Viewpoint
Two-Sided Lighting
Separate Specular Color
Enabling Lighting
Defining Material Properties
Diffuse and Ambient Reflection
Specular Reflection
Emission
Changing Material Properties
Color Material Mode
The Mathematics of Lighting
Material Emission
Scaled Global Ambient Light
Contributions from Light Sources
Putting It All Together
Separate Specular Color
Lighting in Color-Index Mode
The Mathematics of Color-Index Mode Lighting
6. Blending, Antialiasing, Fog, and Polygon Offset
Blending
The Source and Destination Factors
Sample Uses of Blending
A Blending Example
Three-Dimensional Blending with the Depth Buffer
Antialiasing
Antialiasing Points or Lines
Antialiasing Polygons
Fog
Using Fog
Fog Equations
Polygon Offset
7. Display Lists
An Example of Using a Display List
Display List Design Philosophy
Creating and Executing a Display List
Naming and Creating a Display List
What's Stored in a Display List?
Executing a Display List
Hierarchical Display Lists
Managing Display List Indices
Executing Multiple Display Lists
Managing State Variables with Display Lists
Encapsulating Mode Changes
8. Drawing Pixels, Bitmaps, Fonts, and Images
Bitmaps and Fonts
The Current Raster Position
Drawing the Bitmap
Choosing a Color for the Bitmap
Fonts and Display Lists
Defining and Using a Complete Font
Images
Reading, Writing, and Copying Pixel Data
Imaging Pipeline
Pixel Packing and Unpacking
Controlling Pixel-Storage Modes
Pixel-Transfer Operations
Pixel Mapping
Magnifying, Reducing, or Flipping an Image
Reading and Drawing Pixel Rectangles
The Pixel Rectangle Drawing Process
Tips for Improving Pixel Drawing Rates
Imaging Subset
Color Tables
Convolutions
Color Matrix
Histogram
Minmax
Combining Pixels Using Blending Equations
Constant Blending Factors
9. Texture Mapping
An Overview and an Example
Steps in Texture Mapping
A Sample Program
Specifying the Texture
Texture Proxy
Replacing All or Part of a Texture Image
One-Dimensional Textures
Three-Dimensional Textures
Using a Texture's Borders
Multiple Levels of Detail
Filtering
Texture Objects
Naming A Texture Object
Creating and Using Texture Objects
Cleaning Up Texture Objects
A Working Set of Resident Textures
Texture Functions
Post-Texture Application of Specular Color
Assigning Texture Coordinates
Computing Appropriate Texture Coordinates
Repeating and Clamping Textures
Automatic Texture-Coordinate Generation
Creating Contours
Environment Mapping
Advanced Features
The Texture Matrix Stack
Multitexturing
10. The Framebuffer
Buffers and Their Uses
Color Buffers
Clearing Buffers
Selecting Color Buffers for Writing and Reading
Masking Buffers
Testing and Operating on Fragments
Scissor Test
Alpha Test
Stencil Test
Depth Test
Blending, Dithering, and Logical Operations
The Accumulation Buffer
Scene Antialiasing
Motion Blur
Depth of Field
Soft Shadows
Jittering
11. Tessellators and Quadrics
Polygon Tessellation
Creating a Tessellation Object
Tessellation Callback Routines
Tessellation Properties
Polygon Definition
Deleting a Tessellation Object
Tessellation Performance Tips
Describing GLU Errors
Backward Compatibility
Quadrics: Rendering Spheres, Cylinders, and Disks
Managing Quadrics Objects
Controlling Quadrics Attributes
Quadrics Primitives
12. Evaluators and NURBS
Prerequisites
Evaluators
One-Dimensional Evaluators
Two-Dimensional Evaluators
Using Evaluators for Textures
The GLU NURBS Interface
A Simple NURBS Example
Managing a NURBS Object
Creating a NURBS Curve or Surface
Trimming a NURBS Surface
13. Selection and Feedback
Selection
The Basic Steps
Creating the Name Stack
The Hit Record
A Selection Example
Picking
Hints for Writing a Program That Uses Selection
Feedback
The Feedback Array
Using Markers in Feedback Mode
A Feedback Example
14. Now That You Know
Error Handling
Which Version Am I Using?
Utility Library Version
Window System Extension Versions
Extensions to the Standard
Extensions to the Standard for Microsoft Windows (WGL)
Cheesy Translucency
An Easy Fade Effect
Object Selection Using the Back Buffer
Cheap Image Transformation
Displaying Layers
Antialiased Characters
Drawing Round Points
Interpolating Images
Making Decals
Drawing Filled, Concave Polygons Using the Stencil Buffer
Finding Interference Regions
Shadows
Hidden-Line Removal
Hidden-Line Removal with Polygon Offset
Hidden-Line Removal with the Stencil Buffer
Texture Mapping Applications
Drawing Depth-Buffered Images
Dirichlet Domains
Life in the Stencil Buffer
Alternative Uses for glDrawPixels() and glCopyPixels()
A. Order of Operations
Overview
Geometric Operations
Per-Vertex Operations
Primitive Assembly
Pixel Operations
Texture Memory
Fragment Operations
Odds and Ends
B. State Variables
The Query Commands
OpenGL State Variables
Current Values and Associated Data
Vertex Array
Transformation
Coloring
Lighting
Rasterization
Texturing
Pixel Operations
Framebuffer Control
Pixels
Evaluators
Hints
Implementation-Dependent Values
Implementation-Dependent Pixel Depths
Miscellaneous
C. OpenGL and Window Systems
GLX: OpenGL Extension for the X Window System
Initialization
Controlling Rendering
GLX Prototypes
AGL: OpenGL Extensions for the Apple Macintosh
Initialization
Rendering and Contexts
Managing an OpenGL Rendering Context
On-Screen Rendering
Off-Screen Rendering
Full-Screen Rendering
Swapping Buffers
Updating the Rendering Buffers
Using an Apple Macintosh Font
Error Handling
AGL Prototypes
PGL: OpenGL Extension for IBM OS/2 Warp
Initialization
Controlling Rendering
PGL Prototypes
WGL: OpenGL Extension for Microsoft Windows 95/98/NT
Initialization
Controlling Rendering
WGL Prototypes
D. Basics of GLUT: The OpenGL Utility Toolkit
Initializing and Creating a Window
Handling Window and Input Events
Loading the Color Map
Initializing and Drawing Three-Dimensional Objects
Managing a Background Process
Running the Program
E. Calculating Normal Vectors
Finding Normals for Analytic Surfaces
Finding Normals from Polygonal Data
F. Homogeneous Coordinates and Transformation Matrices
Homogeneous Coordinates
Transforming Vertices
Transforming Normals
Transformation Matrices
Translation
Scaling
Rotation
Perspective Projection
Orthographic Projection
G. Programming Tips
OpenGL Correctness Tips
OpenGL Performance Tips
GLX Tips
H. OpenGL Invariance
Glossary
Index
Forewords & Introductions
The OpenGL graphics system is a software interface to graphics hardware. (The GL stands for Graphics Library.) It allows you to create interactive programs that produce color images of moving three-dimensional objects. With OpenGL, you can control computer-graphics technology to produce realistic pictures or ones that depart from reality in imaginative ways. This guide explains how to program with the OpenGL graphics system to deliver the visual effect you want.
What This Guide Contains
This guide has 14 chapters. The first five chapters present basic information that you need to understand to be able to draw a properly colored and lit three-dimensional object on the screen.
Chapter 1, "Introduction to OpenGL," provides a glimpse into the kinds of things OpenGL can do. It also presents a simple OpenGL program and explains essential programming details you need to know for subsequent chapters.
Chapter 2, "State Management and Drawing Geometric Objects," explains how to create a three-dimensional geometric description of an object that is eventually drawn on the screen.
Chapter 3, "Viewing," describes how such three-dimensional models are transformed before being drawn on a two-dimensional screen. You can control these transformations to show a particular view of a model.
Chapter 4, "Color," describes how to specify the color and shading method used to draw an object.
Chapter 5, "Lighting," explains how to control the lighting conditions surrounding an object and how that object responds to light (that is, how it reflects or absorbs light). Lighting is an important topic, since objects usually don't look three-dimensionaluntil they're lit. The remaining chapters explain how to optimize or add sophisticated features to your three-dimensional scene. You might choose not to take advantage of many of these features until you're more comfortable with OpenGL. Particularly advanced topics are noted in the text where they occur.
Chapter 6, "Blending, Antialiasing, Fog, and Polygon Offset," describes techniques essential to creating a realistic scene--alpha blending (to create transparent objects), antialiasing (to eliminate jagged edges), atmospheric effects (to simulate fog or smog), and polygon offset (to remove visual artifacts when highlighting the edges of filled polygons).
Chapter 7, "Display Lists," discusses how to store a series of OpenGL commands for execution at a later time. You'll want to use this feature to increase the performance of your OpenGL program.
Chapter 8, "Drawing Pixels, Bitmaps, Fonts, and Images," discusses how to work with sets of two-dimensional data as bitmaps or images. One typical use for bitmaps is describing characters in fonts.
Chapter 9, "Texture Mapping," explains how to map one- and two-dimensional images called textures onto three-dimensional objects. Many marvelous effects can be achieved through texture mapping.
Chapter 10, "The Framebuffer," describes all the possible buffers that can exist in an OpenGL implementation and how you can control them. You can use the buffers for such effects as hidden-surface elimination, stenciling, masking, motion blur, and depth-of-field focusing.
Chapter 11, "Tessellators and Quadrics," shows how to use the tessellation and quadrics routines in the GLU (OpenGL Utility Library).
Chapter 12, "Evaluators and NURBS," gives an introduction to advanced techniques for efficient generation of curves or surfaces.
Chapter 13, "Selection and Feedback," explains how you can use OpenGL's selection mechanism to select an object on the screen. Additionally, the chapter also explains the feedback mechanism, which allows you to collect the drawing information OpenGL produces rather than having it be used to draw on the screen.
Chapter 14, "Now That You Know," describes how to use OpenGL in several clever and unexpected ways to produce interesting results. These techniques are drawn from years of experience with both OpenGL and the technological precursor to OpenGL, the Silicon Graphics IRIS Graphics Library. In addition, there are several appendices that you will likely find useful.
Appendix A, "Order of Operations," gives a technical overview of the operations OpenGL performs, briefly describing them in the order in which they occur as an application executes.
Appendix B, "State Variables," lists the state variables that OpenGL maintains and describes how to obtain their values.
Appendix C, "OpenGL and Window Systems," briefly describes the routines available in window-system-specific libraries, which are extended to support OpenGL rendering. Window system interfaces to the X Window System, Apple MacIntosh, IBM OS/2, and Microsoft Windows NT and Windows 95 are discussed here.
Appendix D, "Basics of GLUT: The OpenGL Utility Toolkit," discusses the library that handles window system operations. GLUT is portable and it makes code examples shorter and more comprehensible.
Appendix E, "Calculating Normal Vectors," tells you how to calculate normal vectors for different types of geometric objects.
Appendix F, "Homogeneous Coordinates and Transformation Matrices," explains some of the mathematics behind matrix transformations.
Appendix G, "Programming Tips," lists some programming tips based on the intentions of the designers of OpenGL that you might find useful.
Appendix H, "OpenGL Invariance," describes when and where an OpenGL implementation must generate the exact pixel values described in the OpenGL specification.
Finally, an extensive Glossary defines the key terms used in this guide.
What's New in This Edition
The third edition of the OpenGL Programming Guide includes this new material:
- Coverage of the following new core capabilities of OpenGL Version 1.2 have been added:
-New vertex array functionality
-Rescaling vertex normals
-New pixel formats (packed pixels and BGRA)
-Texturing enhancements, including 3D textures, texture coordinate edge clamping, new level of detail control, and support for specular highlights to be applied after texturing
- Descriptions of the following new optional capabilities of OpenGL Version 1.2 have been added
-The OpenGL imaging subset, which is a set of advanced image processing operations
-Multitexturing
- Documentation of new routines in Version 1.3 of GLU (OpenGL Utility Library)
- Introduction to additional functionality in Version 1.3 of GLX (OpenGL Extension to the X Window System)
- Bug fixes for the 2nd edition
What You Should Know Before Reading This Guide
This guide assumes only that you know how to program in the C language and that you have some background in mathematics (geometry, trigonometry, linear algebra, calculus, and differential geometry). Even if you have little or no experience with computer-graphics technology, you should be able to follow most of the discussions in this book. Of course, computer graphics is a huge subject, so you may want to enrich your learning experience with supplemental reading.
Computer Graphics: Principles and Practice by James D. Foley, Andries van Dam, Steven K. Feiner, and John F. Hughes (Reading, MA: Addison-Wesley, 1990)--This book is an encyclopedic treatment of the subject of computer graphics. It includes a wealth of information but is probably best read after you have some experience with the subject.
3D Computer Graphics: A User's Guide for Artists and Designers by Andrew S. Glassner (New York: Design Press, 1989)--This book is a nontechnical, gentle introduction to computer graphics. It focuses on the visual effects that can be achieved rather than on the techniques needed to achieve them.
Another great place for all sorts of general information is the Official OpenGL Web Site. This Web site contains software, documentation, FAQs, and news. It is always a good place to start any search for answers to your OpenGL questions.
Once you begin programming with OpenGL, you might want to obtain the our siteOpenGL Reference Manual by the OpenGL Architecture Review Board (Reading, MA: Addison-Wesley), which is designed as a companion volume to this guide. The Reference Manual provides a technical view of how OpenGL operates on data that describes a geometric object or an image to produce an image on the screen. It also contains full descriptions of each set of related OpenGL commands--the parameters used by the commands, the default values for those parameters, and what the commands accomplish. Many OpenGL implementations have this same material on-line, in the form of manual pages or other help documents, which are probably more up-to-date. There are also versions on the World Wide Web; consult the previously mentioned Official OpenGL Web Site.
OpenGL is really a hardware-independent specification of a programming interface, and you use a particular implementation of it on a particular kind of hardware. This guide explains how to program with any OpenGL implementation. However, since implementations may vary slightly--in performance and in providing additional, optional features, for example--you might want to investigate whether supplementary documentation is available for the particular implementation you're using. In addition, you might have OpenGL-related utilities, toolkits, programming and debugging support, widgets, sample programs, and demos available to you with your system.
How to Obtain the Sample Code
This guide contains many sample programs to illustrate the use of particular OpenGL programming techniques. These programs make use of Mark Kilgard's OpenGL Utility Toolkit (GLUT). GLUT is documented in our siteOpenGL Programming for the X Window System by Mark Kilgard (Reading, MA: Addison-Wesley Developers Press, 1996). The section "OpenGL-Related Libraries" in Chapter 1 and Appendix D give more information about using GLUT. If you have access to the Internet, you can obtain the source code for both the sample programs and GLUT for free via anonymous ftp (file-transfer protocol).
For the source code examples found in this book, download the files from the ftp site
For Mark Kilgard's source code for GLUT (for Microsoft Windows 95/98/NT or the X Window System), check this Web page to find out what current version of GLUT is available and from where to download the source code.
Many implementations of OpenGL might also include the code samples as part of the system. This source code is probably the best source for your implementation, because it might have been optimized for your system. Read your machine-specific OpenGL documentation to see where the code samples can be found.
Nate Robins' OpenGL Tutors
Nate Robins has written a suite of tutorial programs that demonstrate basic OpenGL programming concepts by allowing the user to modify the parameters of a function and interactively see their effects. Topics covered include transformations, lighting, fog, and texturing. These highly recommended tutorials are portable and require the aforementioned GLUT.
Read an Excerpt
About This Guide
The OpenGL graphics system is a software interface to graphics hardware. (The GL stands for Graphics Library.) It allows you to create interactive programs that produce color images of moving three-dimensional objects. With OpenGL, you can control computer-graphics technology to produce realistic pictures or ones that depart from reality in imaginative ways. This guide explains how to program with the OpenGL graphics system to deliver the visual effect you want.
What This Guide Contains
This guide has 14 chapters. The first five chapters present basic information that you need to understand to be able to draw a properly colored and lit three-dimensional object on the screen.
* Chapter: 1, "Introduction to OpenGL," provides a glimpse into the kinds of things OpenGL can do. It also presents a simple OpenGL program and explains essential programming details you need to know for subsequent chapters.
* Chapter: 2, "State Management and Drawing Geometric Objects," explains how to create a three-dimensional geometric description of an object that is eventually drawn on the screen.
* Chapter: 3, "Viewing," describes how such three-dimensional models are transformed before being drawn on a two-dimensional screen. You can control these transformations to show a particular view of a model.
* Chapter: 4, "Color," describes how to specify the color and shading method used to draw an object.
* Chapter: 5, "Lighting," explains how to control the lighting conditions surrounding an object and how that object responds to light (that is, how it reflects or absorbs light). Lighting is an important topic, since objects usually don't look three-dimensional until they're lit.
The remaining chapters explain how to optimize or add sophisticated features to your three-dimensional scene. You might choose not to take advantage of many of these features until you're more comfortable with OpenGL. Particularly advanced topics are noted in the text where they occur.
* Chapter: 6, "Blending, Antialiasing, Fog, and Polygon Offset," describes techniques essential to creating a realistic scene-alpha blending (to create transparent objects), antialiasing (to eliminate jagged edges), atmospheric effects (to simulate fog or smog), and polygon offset (to remove visual artifacts when highlighting the edges of filled polygons).
* Chapter: 7, "Display Lists," discusses how to store a series of OpenGL commands for execution at a later time. You'll want to use this feature to increase the performance of your OpenGL program.
* Chapter: 8, "Drawing Pixels, Bitmaps, Fonts, and Images," discusses how to work with sets of two-dimensional data as bitmaps or images. One typical use for bitmaps is describing characters in fonts.
* Chapter: 9, "Texture Mapping," explains how to map one- and two-dimensional images called textures onto three-dimensional objects. Many marvelous effects can be achieved through texture mapping.
* Chapter: 10, "The Framebuffer," describes all the possible buffers that can exist in an OpenGL implementation and how you can control them. You can use the buffers for such effects as hidden-surface elimination, stenciling, masking, motion blur, and depth-of-field focusing.
* Chapter: 11, "Tessellators and Quadrics," shows how to use the tessellation and quadrics routines in the GLU (OpenGL Utility Library).
* Chapter: 12, "Evaluators and NURBS," gives an introduction to advanced techniques for efficient generation of curves or surfaces.
* Chapter: 13, "Selection and Feedback," explains how you can use OpenGL's selection mechanism to select an object on the screen. Additionally, the chapter also explains the feedback mechanism, which allows you to collect the drawing information OpenGL produces rather than having it be used to draw on the screen.
* Chapter: 14, "Now That You Know," describes how to use OpenGL in several clever and unexpected ways to produce interesting results. These techniques are drawn from years of experience with both OpenGL and the technological precursor to OpenGL, the Silicon Graphics IRIS Graphics Library.
In addition, there are several appendices that you will likely find useful.
Appendix: A, "Order of Operations," gives a technical overview of the operations OpenGL performs, briefly describing them in the order in which they occur as an application executes.
* Appendix: B, "State Variables," lists the state variables that OpenGL maintains and describes how to obtain their values.
* Appendix: C, "OpenGL and Window Systems," briefly describes the routines available in window-system-specific libraries, which are extended to support OpenGL rendering. Window system interfaces to the X Window System, Apple MacIntosh, IBM OS/2, and Microsoft Windows NT and Windows 95 are discussed here.
* Appendix: D, "Basics of GLUT: The OpenGL Utility Toolkit," discusses the library that handles window system operations. GLUT is portable and it makes code examples shorter and more comprehensible.
* Appendix: E, "Calculating Normal Vectors," tells you how to calculate normal vectors for different types of geometric objects.
* Appendix: F, "Homogeneous Coordinates and Transformation Matrices," explains some of the mathematics behind matrix transformations.
* Appendix: G, "Programming Tips," lists some programming tips based on the intentions of the designers of OpenGL that you might find useful.
* Appendix: H, "OpenGL Invariance," describes when and where an OpenGL implementation must generate the exact pixel values described in the OpenGL specification.
Finally, an extensive Glossary defines the key terms used in this guide.
What's New in This Edition
The third edition of the OpenGL Programming Guide includes this new material:
* Coverage of the following new core capabilities of OpenGL Version 1.2 have been added
New vertex array functionality
_ Rescaling vertex normals
_ New pixel formats (packed pixels and BGRA)
_ Texturing enhancements, including 3D textures, texture coordinate edge clamping, new level of detail control, and support for specular highlights to be applied after texturing
* Descriptions of the following new optional capabilities of OpenGL Version 1.2 have been added
_ The OpenGL imaging subset, which is a set of advanced image processing operations
_ Multitexturing
* Documentation of new routines in Version 1.3 of GLU (OpenGL Utility Library)
* Introduction to additional functionality in Version 1.3 of GLX (OpenGL Extension to the X Window System)
* Bug fixes for the 2nd edition
What You Should Know Before Reading This Guide
This guide assumes only that you know how to program in the C language and that you have some background in mathematics (geometry, trigonometry, linear algebra, calculus, and differential geometry). Even if you have little or no experience with computer-graphics technology, you should be able to follow most of the discussions in this book. Of course, computer graphics is a huge subject, so you may want to enrich your learning experience with supplemental reading.
* Computer Graphics: Principles and Practice by James D. Foley, Andries van Dam, Steven K. Feiner, and John F. Hughes (Reading, MA: Addison-Wesley, 1990)-This book is an encyclopedic treatment of the subject of computer graphics. It includes a wealth of information but is probably best read after you have some experience with the subject.
* 3D Computer Graphics: A User's Guide for Artists and Designers by Andrew S. Glassner (New York: Design Press, 1989)-This book is a nontechnical, gentle introduction to computer graphics. It focuses on the visual effects that can be achieved rather than on the techniques needed to achieve them.
Another great place for all sorts of general information is the Official OpenGL Web Site. This Web site contains software, documentation, FAQs, and news. It is always a good place to start any search for answers to your OpenGL questions.
Once you begin programming with OpenGL, you might want to obtain the
OpenGL Reference Manual
OpenGL Reference Manual by the OpenGL Architecture Review Board (Reading, MA: Addison-Wesley), which is designed as a companion volume to this guide. The Reference Manual provides a technical view of how OpenGL operates on data that describes a geometric object or an image to produce an image on the screen. It also contains full descriptions of each set of related OpenGL commands-the parameters used by the commands, the default values for those parameters, and what the commands accomplish. Many OpenGL implementations have this same material on-line, in the form of manual pages or other help documents, which are probably more up-to-date. There are also versions on the World Wide Web; consult the previously mentioned Official OpenGL Web Site.
OpenGL is really a hardware-independent specification of a programming interface, and you use a particular implementation of it on a particular kind of hardware. This guide explains how to program with any OpenGL implementation. However, since implementations may vary slightly-in performance and in providing additional, optional features, for example-you might want to investigate whether supplementary documentation is available for the particular implementation you're using. In addition, you might have OpenGL-related utilities, toolkits, programming and debugging support, widgets, sample programs, and demos available to you with your system.
How to Obtain the Sample Code
This guide contains many sample programs to illustrate the use of particular OpenGL programming techniques. These programs make use of Mark Kilgard's OpenGL Utility Toolkit (GLUT). GLUT is documented in OpenGL Programming for the X Window System by Mark Kilgard (Reading, MA: Addison-Wesley Developers Press, 1996). The section "OpenGL-Related Libraries" in Chapter 1 and Appendix: D give more information about using GLUT. If you have access to the Internet, you can obtain the source code for both the sample programs and GLUT for free via anonymous ftp (file-transfer protocol).
For the source code examples found in this book, grab either of these files (depending on which decompression/extraction tools you have):
ftp://sgigate.sgi.com/pub/opengl/opengl12.tar.Z
ftp://sgigate.sgi.com/pub/opengl/opengl12.zip
Use the appropriate tools to uncompress and/or extract the source code from these archive files.
For Mark Kilgard's source code for GLUT (for Microsoft Windows 95/98/NT or the X Window System), check this Web page to find out what current version of GLUT is available and from where to download the source code.
Many implementations of OpenGL might also include the code samples as part of the system. This source code is probably the best source for your implementation, because it might have been optimized for your system. Read your machine-specific OpenGL documentation to see where the code samples can be found.
Nate Robins' OpenGL Tutors
Nate Robins has written a suite of tutorial programs that demonstrate basic OpenGL programming concepts by allowing the user to modify the parameters of a function and interactively see their effects. Topics covered include transformations, lighting, fog, and texturing. These highly recommended tutorials are portable and require the aforementioned GLUT.
Errata
Undoubtedly this book has errors. An error list is maintained on the web.
If you find any bugs, you can use the pointer at this Web site to report them.
Style Conventions
These style conventions are used in this guide:
* Bold-Command and routine names and matrices
* Italics-Variables, arguments, parameter names, spatial dimensions, matrix components, and first occurrences of key terms
* Regular-Enumerated types and defined constants
Code examples are set off from the text in a monospace font, and command summaries are shaded with gray boxes.
In a command summary, braces are used to identify choices among data types. In the following example, glCommand has four possible suffixes: s, i, f, and d, which stand for the data types GLshort, GLint, GLfloat, and GLdouble. In the function prototype for glCommand, TYPE is a wildcard that represents the data type indicated by the suffix.
void glCommand{sifd}(TYPE x1, TYPE y1, TYPE x2, TYPE y2);