OpenGL® Examples



Redbook

View Image Description View Source
aaindex.jpg 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. aaindex.c
aargb.jpg 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. aargb.c
accanti.jpg A simple example of using accumulation buffer to anti-alias. accanti.c
accpersp.jpg Use the accumulation buffer to do full-scene antialiasing on a scene with perspective projection, using the special routines accFrustum() and accPerspective(). accpersp.c
alpha.jpg 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. alpha.c
alpha3D.jpg 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. alpha3D.c
bezcurve.jpg This program uses evaluators to draw a Bezier curve. bezcurve.c
bezmesh.jpg This program renders a lighted, filled Bezier surface, using two-dimensional evaluators. bezmesh.c
bezsurf.jpg This program renders a wireframe Bezier surface, using two-dimensional evaluators. bezsurf.c
checker.jpg 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. checker.c
clip.jpg This program demonstrates arbitrary clipping planes. clip.c
colormat.jpg After initialization, the program will be in ColorMaterial mode. Interaction: pressing the mouse buttons will change the diffuse reflection values. colormat.c
cube.jpg This program demonstrates a single modeling transformation, glScalef() and a single viewing transformation, gluLookAt(). A wireframe box is rendered. cube.c
dof.jpg 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. dof.c
double.jpg This is a simple double buffered program. Pressing the left mouse button rotates the rectangle. Pressing the middle mouse button stops the rotation. double.c
drawf.jpg Draws the bitmapped letter F on the screen (several times). This demonstrates use of the glBitmap() call. drawf.c
feedback.jpg 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. feedback.c
fog.jpg 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. fog.c
fogindex.jpg 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. fogindex.c
hello.jpg This is a simple, introductory OpenGL program. hello.c
image.jpg 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. image.c
light.jpg 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. light.c
lines.jpg This program demonstrates geometric primitives and their attributes. lines.c
list.jpg This program demonstrates how to make and execute a display list. Note that attributes, such as current color and matrix, are changed. list.c
material.jpg 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. material.c
mipmap.jpg 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. mipmap.c
model.jpg 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. model.c
movelight.jpg 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.
movelight.c
pickdepth.jpg 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. pickdepth.c
picksquare.jpg 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. picksquare.c
planet.jpg 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. planet.c
polyoff.jpg This program demonstrates polygon offset to draw a shaded polygon and its wireframe counterpart without ugly visual artifacts ("stitching"). polyoff.c
polys.jpg This program demonstrates polygon stippling. polys.c
quadric.jpg 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. quadric.c
robot.jpg 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. robot.c
scene.jpg 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. scene.c
select.jpg 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. select.c
smooth.jpg This program demonstrates smooth shading. A smooth shaded polygon is drawn in a 2-D projection. smooth.c
stencil.jpg 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. stencil.c
stroke.jpg 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. stroke.c
surface.jpg This program draws a NURBS surface in the shape of a symmetrical hill. surface.c
teapots.jpg This program demonstrates lots of material properties. A single light source illuminates the objects. teapots.c
tess.jpg 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).
tess.c
tesswind.jpg 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. tesswind.c
texbind.jpg This program demonstrates using glBindTexture() by creating and managing two textures. texbind.c
texgen.jpg 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. texgen.c
texsub.jpg 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. texsub.c
texturesurf.jpg This program uses evaluators to generate a curved surface and automatically generated texture coordinates. texturesurf.c
torus.jpg This program demonstrates the creation of a display list. torus.c
trim.jpg 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. trim.c
varray.jpg This program demonstrates vertex arrays. varray.c
wrap.jpg 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.
wrap.c