|Download Files|
GLUT-based source from OpenGL Redbook, v1.1
These are the example programs which are featured in the OpenGL
Programming Guide, Version 1.1. To compile these programs, you
need OpenGL development libraries for your machine and Mark Kilgard's
GLUT (Graphics Library Utility Toolkit).
There is a simple Imakefile in this directory,
which can be used to create a Makefile to compile the example
programs. There is also a Makefile.win32,
which has been tested on Windows-based PCs (and an nmake-based file is
also included in Makefile.nmake).
When using either the Imakefile or one of the Makefiles,
you will probably need to modify some of the variables inside the
files to make sure that GLUT headers and libraries are correctly
included and linked.
The Imakefile should generate a good Makefile with a simple
command such as:
% imake -DUseInstalled -I/usr/lib/X11/config
There are a handful of modifications from the code which is
printed in the OpenGL Programming Guide. Most noticeably, every
program (except for hello.c and
double.c, which are featured in
the first chapter) has a keyboard callback function to exit the
program when the ESCape key is pressed.
- Changes between this directory and the examples printed in the book
Also, after the book went to press, a couple of discrepancies
between the UNIX and MS Windows compilers became noticeable, requiring
changes to the source code. Most obviously, all PC programs had to
include <windows.h> before <gl.h> or <glu.h>.
GLUT already does this in the correct order, so the simplest solution
was to only include <GL/glut.h> and to let it include (if
needed) the windows.h, gl.h, and glu.h files, in the correct order.
The torus.c program refers to a symbolic constant
M_PI, which may not be found on MS Windows based systems. A new constant
PI_ has replaced it and is defined within the program.
Several programs use callback functions. The method of casting
those callback functions worked fine on UNIX based systems, but
not on PCs. The programs quadric.c,
surface.c, trim.c,
tess.c, and tesswind.c
have been modified. References to (GLvoid (*))
cast have been removed, and a reference to the CALLBACK type
has been added to the declaration of the callback functions.
Where CALLBACK is undefined (for instance, in UNIX systems),
it is stubbed out by use of #ifndef.
The programs accpersp.c
and dof.c used the variable names "near"
and "far" which are reserved words for PC compilers. If needed,
these variables names are now redefined during pre-processing
(by using #ifdef).
- OpenGL 1.0 to 1.1 compatibility issues
Most of these programs also run well on OpenGL 1.0. There are
nine programs which use features not found in OpenGL 1.0. The
four programs checker.c,
mipmap.c, texgen.c,
and wrap.c use
texture objects, and have been modified so that they will avoid
the use of texture objects on OpenGL 1.1 machines. So these
programs will still run well on OpenGL 1.0.
The five programs polyoff.c,
texbind.c, texprox.c,
texsub.c, and varray.c
demonstrate features which are new in OpenGL 1.1.
On OpenGL 1.0, these five programs will not run; instead an error
message will be printed out. If your implementation of OpenGL 1.0
supports polygon offset, vertex array, and/or texture extensions,
you may be able to modify the code to run on your implementation.
Thank you.
Mason Woo, co-author OpenGL Programming Guide, Version 1.1
mason@woo.com
 |
This program shows how to draw anti-aliased lines in color
index mode. It draws two diagonal lines to form an X; when 'r'
is typed in the window, the lines are rotated in opposite
directions.
Source code: aaindex.c.
Executable: aaindex.bat.
Snapshots: aaindex (shown).
|
 |
This program shows how to draw anti-aliased lines. It draws
two diagonal lines to form an X; when 'r' is typed in the window,
the lines are rotated in opposite directions.
Source code: aargb.c.
Executable: aargb.bat.
Snapshots: aargb (shown).
|
 |
Use the accumulation buffer to do full-scene antialiasing
on a scene with perspective projection, using the special
routines accFrustum() and accPerspective().
Source code: accpersp.c.
Executable: accpersp.bat.
Snapshots: accpersp (shown).
|
 |
This program draws several overlapping filled polygons
to demonstrate the effect order has on alpha blending results.
Use the 't' key to toggle the order of drawing polygons.
Source code: alpha.c.
Executable: alpha.bat.
Snapshots: alpha (shown).
|
 |
This program demonstrates how to intermix opaque and
alpha blended polygons in the same scene, by using
glDepthMask. Press the 'a' key to animate moving the
transparent object through the opaque object. Press
the 'r' key to reset the scene.
Source code: alpha3D.c.
Executable: alpha3D.bat.
Snapshots: alpha3D (shown).
|
 |
This program texture maps a checkerboard image onto
two rectangles. This program clamps the texture, if
the texture coordinates fall outside 0.0 and 1.0.
Source code: checker.c.
Executable: checker.bat.
Snapshots: checker (shown).
|
 |
After initialization, the program will be in
ColorMaterial mode. Interaction: pressing the
mouse buttons will change the diffuse reflection values.
Source code: colormat.c.
Executable: colormat.bat.
Snapshots: colormat (shown).
|
 |
This program demonstrates a single modeling transformation,
glScalef() and a single viewing transformation, gluLookAt().
A wireframe box is rendered.
Source code: cube.c.
Executable: cube.bat.
Snapshots: cube (shown).
|
 |
This program demonstrates use of the accumulation buffer to
create an out-of-focus depth-of-field effect. The teapots
are drawn several times into the accumulation buffer. The
viewing volume is jittered, except at the focal point, where
the viewing volume is at the same position, each time. In
this case, the gold teapot remains in focus.
Source code: dof.c.
Executable: dof.bat.
Snapshots: dof (shown).
|
 |
This is a simple double buffered program.
Pressing the left mouse button rotates the rectangle.
Pressing the middle mouse button stops the rotation.
Source code: double.c.
Executable: double.bat.
Snapshots: double (shown).
|
 |
Draws the bitmapped letter F on the screen (several times).
This demonstrates use of the glBitmap() call.
Source code: drawf.c.
Executable: drawf.bat.
Snapshots: drawf (shown).
|
 |
This program demonstrates use of OpenGL feedback. First,
a lighting environment is set up and a few lines are drawn.
Then feedback mode is entered, and the same lines are
drawn. The results in the feedback buffer are printed.
Source code: feedback.c.
Executable: feedback.bat.
Snapshots: feedback (shown).
|
 |
This program draws 5 red teapots, each at a different
z distance from the eye, in different types of fog.
Pressing the left mouse button chooses between 3 types of
fog: exponential, exponential squared, and linear.
In this program, there is a fixed density value, as well
as fixed start and end values for the linear fog.
Source code: fog.c.
Executable: fog.bat.
Snapshots: fog (shown).
|
 |
This program demonstrates fog in color index mode.
Three cones are drawn at different z values in a linear
fog. 32 contiguous colors (from 16 to 47) are loaded
with a color ramp.
Source code: fogindex.c.
Executable: fogindex.bat.
Snapshots: fogindex (shown).
|
 |
This program demonstrates drawing pixels and shows the effect
of glDrawPixels(), glCopyPixels(), and glPixelZoom().
Interaction: moving the mouse while pressing the mouse button
will copy the image in the lower-left corner of the window
to the mouse position, using the current pixel zoom factors.
There is no attempt to prevent you from drawing over the original
image. If you press the 'r' key, the original image and zoom
factors are reset. If you press the 'z' or 'Z' keys, you change
the zoom factors.
Source code: image.c.
Executable: image.bat.
Snapshots: image (shown).
|
 |
This program demonstrates the use of the OpenGL lighting
model. A sphere is drawn using a grey material characteristic.
A single light source illuminates the object.
Source code: light.c.
Executable: light.bat.
Snapshots: light (shown).
|
 |
This program demonstrates how to make and execute a
display list. Note that attributes, such as current
color and matrix, are changed.
Source code: list.c.
Executable: list.bat.
Snapshots: list (shown).
|
 |
This program demonstrates the use of the GL lighting model.
Several objects are drawn using different material characteristics.
A single light source illuminates the objects.
Source code: material.c.
Executable: material.bat.
Snapshots: material (shown).
|
 |
This program demonstrates using mipmaps for texture maps.
To overtly show the effect of mipmaps, each mipmap reduction
level has a solidly colored, contrasting texture image.
Thus, the quadrilateral which is drawn is drawn with several
different colors.
Source code: mipmap.c.
Executable: mipmap.bat.
Snapshots: mipmap (shown).
|
 |
This program demonstrates using mipmaps for texture maps.
To overtly show the effect of mipmaps, each mipmap reduction
level has a solidly colored, contrasting texture image.
Thus, the quadrilateral which is drawn is drawn with several
different colors.
Source code: model.c.
Executable: model.bat.
Snapshots: model (shown).
|
 |
This program demonstrates when to issue lighting and
transformation commands to render a model with a light
which is moved by a modeling transformation (rotate or
translate). The light position is reset after the modeling
transformation is called. The eye position does not change.
A sphere is drawn using a grey material characteristic.
A single light source illuminates the object.
Interaction: pressing the left mouse button alters
the modeling transformation (x rotation) by 30 degrees.
The scene is then redrawn with the light in a new position.
Source code: movelight.c.
Executable: movelight.bat.
Snapshots: movelight (shown).
|
 |
Picking is demonstrated in this program. In
rendering mode, three overlapping rectangles are
drawn. When the left mouse button is pressed,
selection mode is entered with the picking matrix.
Rectangles which are drawn under the cursor position
are "picked." Pay special attention to the depth
value range, which is returned.
Source code: pickdepth.c.
Executable: pickdepth.bat.
Snapshots: pickdepth (shown).
|
 |
Use of multiple names and picking are demonstrated.
A 3x3 grid of squares is drawn. When the left mouse
button is pressed, all squares under the cursor position
have their color changed.
Source code: picksquare.c.
Executable: picksquare.bat.
Snapshots: picksquare (shown).
|
 |
This program shows how to composite modeling transformations
to draw translated and rotated models.
Interaction: pressing the d and y keys (day and year)
alters the rotation of the planet around the sun.
Source code: planet.c.
Executable: planet.bat.
Snapshots: planet (shown).
|
 |
This program demonstrates polygon offset to draw a shaded
polygon and its wireframe counterpart without ugly visual
artifacts ("stitching").
Source code: polyoff.c.
Executable: polyoff.bat.
Snapshots: polyoff (shown).
|
 |
This program demonstrates the use of some of the gluQuadric*
routines. Quadric objects are created with some quadric
properties and the callback routine to handle errors.
Note that the cylinder has no top or bottom and the circle
has a hole in it.
Source code: quadric.c.
Executable: quadric.bat.
Snapshots: quadric (shown).
|
 |
This program shows how to composite modeling transformations
to draw translated and rotated hierarchical models.
Interaction: pressing the s and e keys (shoulder and elbow)
alters the rotation of the robot arm.
Source code: robot.c.
Executable: robot.bat.
Snapshots: robot (shown).
|
 |
This program demonstrates the use of the GL lighting model.
Objects are drawn using a grey material characteristic.
A single light source illuminates the objects.
Source code: scene.c.
Executable: scene.bat.
Snapshots: scene (shown).
|
 |
This is an illustration of the selection mode and
name stack, which detects whether objects which collide
with a viewing volume. First, four triangles and a
rectangular box representing a viewing volume are drawn
(drawScene routine). The green triangle and yellow
triangles appear to lie within the viewing volume, but
the red triangle appears to lie outside it. Then the
selection mode is entered (selectObjects routine).
Drawing to the screen ceases. To see if any collisions
occur, the four triangles are called. In this example,
the green triangle causes one hit with the name 1, and
the yellow triangles cause one hit with the name 3.
Source code: select.c.
Executable: select.bat.
Snapshots: select (shown).
|
 |
This program demonstrates smooth shading.
A smooth shaded polygon is drawn in a 2-D projection.
Source code: smooth.c.
Executable: smooth.bat.
Snapshots: smooth (shown).
|
 |
This program draws two rotated tori in a window.
A diamond in the center of the window masks out part
of the scene. Within this mask, a different model
(a sphere) is drawn in a different color.
Source code: stencil.c.
Executable: stencil.bat.
Snapshots: stencil (shown).
|
 |
This program demonstrates some characters of a
stroke (vector) font. The characters are represented
by display lists, which are given numbers which
correspond to the ASCII values of the characters.
Use of glCallLists() is demonstrated.
Source code: stroke.c.
Executable: stroke.bat.
Snapshots: stroke (shown).
|
 |
This program demonstrates lots of material properties.
A single light source illuminates the objects.
Source code: teapots.c.
Executable: teapots.bat.
Snapshots: teapots (shown).
|
 |
This program demonstrates polygon tessellation.
Two tesselated objects are drawn. The first is a
rectangle with a triangular hole. The second is a
smooth shaded, self-intersecting star.
Note the exterior rectangle is drawn with its vertices
in counter-clockwise order, but its interior clockwise.
Note the combineCallback is needed for the self-intersecting
star. Also note that removing the TessProperty for the
star will make the interior unshaded (WINDING_ODD).
Source code: tess.c.
Executable: tess.bat.
Snapshots: tess (shown).
|
 |
This program demonstrates the winding rule polygon
tessellation property. Four tessellated objects are drawn,
each with very different contours. When the w key is pressed,
the objects are drawn with a different winding rule.
Source code: tesswind.c.
Executable: tesswind.bat.
Snapshots: tesswind (shown).
|
 |
This program draws a texture mapped teapot with
automatically generated texture coordinates. The
texture is rendered as stripes on the teapot.
Initially, the object is drawn with texture coordinates
based upon the object coordinates of the vertex
and distance from the plane x = 0. Pressing the 'e'
key changes the coordinate generation to eye coordinates
of the vertex. Pressing the 'o' key switches it back
to the object coordinates. Pressing the 's' key
changes the plane to a slanted one (x + y + z = 0).
Pressing the 'x' key switches it back to x = 0.
Source code: texgen.c.
Executable: texgen.bat.
Snapshots: texgen (shown).
|
 |
This program texture maps a checkerboard image onto
two rectangles. This program clamps the texture, if
the texture coordinates fall outside 0.0 and 1.0.
If the s key is pressed, a texture subimage is used to
alter the original texture. If the r key is pressed,
the original texture is restored.
Source code: texsub.c.
Executable: texsub.bat.
Snapshots: texsub (shown).
|
 |
This program draws a NURBS surface in the shape of a
symmetrical hill, using both a NURBS curve and pwl
(piecewise linear) curve to trim part of the surface.
Source code: trim.c.
Executable: trim.bat.
Snapshots: trim (shown).
|
 |
This program texture maps a checkerboard image onto
two rectangles. This program demonstrates the wrapping
modes, if the texture coordinates fall outside 0.0 and 1.0.
Interaction: Pressing the 's' and 'S' keys switch the
wrapping between clamping and repeating for the s parameter.
The 't' and 'T' keys control the wrapping for the t parameter.
If running this program on OpenGL 1.0, texture objects are
not used.
Source code: wrap.c.
Executable: wrap.bat.
Snapshots: wrap (shown).
|
Web Accessible Files of the src/gfx/opengl/tutorials/redbook directory:
This is an automatically derived categorization of files of this directory.
Only files which can be displayed or heard in some manner are included.
Files may be immediately accessed by clicking the corresponding link. The
Zip Archive (if present) contains all files in this directory/subtree
(including executables, etc.)
Source
Documentation
Images
Reference
Zip Archive
Copyright © 1997-98, Silicon Graphics, Inc.
|