This is a collection of examples to supplement Ed Angel's book
Many of the code examples in the Primer are partial programs.
In this directory you will find these extended to full programs. The directory
is organized as a series of subdirectories keyed to each chapter. Each subdirectory
has its own makefile that will make all of the programs in that directory.
Chapter 2: 2D Programming
- simple.c This is more or less the program
on p.12 of the Primer, and again on p.24. It draws a magenta square on a yellow
- triangle.c This is the twisted triangle
example on p.41 of the Primer.
Chapter 3: Interaction
Portions of this are on p.64 of the Primer. This is the simple spinning
square example on p.53, modified to open two windows: one using single-buffering
and one using double-buffering. You can see the improvement given by double-buffering
in animation situations.
This is the example
on p.73-74 of the Primer.
is an SGI program demoing names and their use with picking.
This is another
SGI program demonstrating selection mode and the name stack.
Chapter 4:Basic 3D Programming
This shows a simple
wire-frame 3D cube.
This is just like
cube.c, only the cube is drawn as a solid with colored sides.
of this is on p.86-89 of the Primer. This is the same program as cube2.c,
only it uses vertex arrays for the points. As a result, we can draw the
cube with only one primitive call.
the same cube as cube2.c. This time there are controls for moving the
viewer's position around. This uses a perspective projection. It also
uses the GLUI library.
Chapter 5: Transformations
of this are on p. 108-109 of the Primer. This shows the same cube as Chapter4/cube3.cpp.
This time there are buttons for rotating the cube about any of its major
This shows a bar
with 3 connected pieces that can be bent independently while staying connected.
It is a simple example of hierarchical modeling.
from bar.cpp only in the way the bar is defined. This time only one rectangle
is specified in terms of vertices, and it is transformed into the three
needed pieces. Note the uses of glPushMatrix() and glPopMatrix().
a simple robot, from pp.116-118 of the Primer.
a simple figure, from pp.118-119 of the Primer.
like figure.cpp, only it uses the node structure described on p.120. The
code for this was pretty vague;this is my interpretation of what was intended.
Note the need to rebuild the model each time any of the angles is changed.
This makes it fairly awkward, in my opinion.
Chapter 6: Lights and Materials
This shows the
same cube as Chapter5/spinCube.cpp. This time we do a lighting calculation
with a red plastic surface. This is more or less the example on p. 132-135,
only Angel has the normals wrong.
This is the
code from Chapter5/figure.cpp, modified to show the figure with a red
This is a
simple example of lighting. A sphere is drawn at the origin. The controls
allow you to move the position of the light source, properties of the
light, and properties of the surface material. The viewer is fixed at
(4, 0, 20). You can use this program to get a feeling for the lighting
and material properties we will discuss in class.
Chapter 7: Images and Bitmaps
draws a simple red square with a nested blue square, as an example of
working with bitmaps.
This shows a checkerboard
bitmap, as on p. 146 of the Primer.
This is one of
Ed Angel's programs. I don't know what itdoes.
displays a portable pixmap image, as discussed in section 7.7 of the Primer.
It prompts the user for the name of an image file. A sample file is included
in this directory: Chapter7/robot2.ppm
is like the ppmdisplay.c program. There may be other differences, but
one distinction is that this one expects a command-line argument with
the name of the ppm file to be displayed.
This is another
program that displays pixmaps. Like ppmdisplay.c, this prompts the user
for the name of the ppm file.
Chapter 8: Texture Mapping
This is the cube
program from Chapter4/cube3.cpp modified to have a checkerboard texture.
This is Angel's
example. It shows a rotating cube with color interpolation. Both normals
and colors are assigned to the vertices.
This is hte same
as cubetex.c, with the cube replaced by a Utah teapot (GLUT has a teapot
Chapter 9: Curves and Surfaces
This is a simple
curve drawing program, shown on p. 200-202.
curve drawing program. This one extends the bezier.c program to include
B-splines and interpolating curves. Parts of this are on p. 204-206.
This is the teapot
example from p. 208-210.
This is the
same as teapot.c with a lighting model and surface texture added.
Chapter 10: Putting It All Together
This is the demo
presented in section 10.1 of the Primer.