Open GL Super Bible

Previous Table of Contents Next


Finally, Some 3D!

Thus far, all our samples have been simple rectangles in the middle of the window; they either scaled to the new window size or bounced around off the walls. By now you may be bouncing off some walls of your own, waiting anxiously to see something in 3D. Wait no more!

As mentioned earlier, we have been drawing in 3D all along, but our view of the rectangle has been perpendicular to the clipping volume. If we could just rotate the clipping volume with respect to the viewer, we might actually see something with a little depth. However, we aren’t going to get into coordinate transformations and rotations until Chapter 7. And even if we started that work now, a flat rectangle isn’t very interesting, even when viewed from an angle.

To see some depth, we need to draw an object that is not flat. The AUX library contains nearly a dozen 3D objects—from a sphere to a teapot—that can be created with a single function call. These called functions are of the form auxSolidxxxx() or auxWirexxxx(), where xxxx names the solid or wireframe object that is created. For example, the following command draws a wireframe teapot of approximately 50.0 units in diameter:

auxWireTeapot(50.0f);

If we define a clipping volume that extends from -100 to 100 along all three axes, we’ll get the wireframe teapot shown in Figure 3-12. The teapot is probably the best example at this point because the other objects still look two-dimensional when viewed from a parallel projection. The program that produced this image is found in this chapter’s subdirectory on the CD in teapot.c.


Figure 3-12  A wireframe teapot

If you change the wire teapot to a solid teapot with the command

auxSolidTeapot(50.0f);

you’ll see only a red outline of the teapot. In order to see relief in a solid-colored object, you will need to incorporate shading and lighting with other OpenGL commands that you’ll learn about in Chapter 9 and later.

For further study of the AUX library objects, see the samples AUXWIRE and AUXSOLID on the CD in this chapter’s subdirectory. These samples make use of the glRotatef() function (explained in Chapter 7), which spins the objects around all three axes of the viewing volume. Some of these objects make use of the utility library, so be sure that you link with glu32.lib when using these objects yourself.

Summary

In this chapter we have introduced the AUX library toolkit and presented the fundamentals of writing a program that uses OpenGL. We have used this library to show the easiest possible way to create a window and draw in it using OpenGL commands. You have learned to use the AUX library to create windows that can be resized, as well as to create simple animation. You have also been introduced to the process of using OpenGL to do drawing—composing and selecting colors, clearing the screen, drawing a rectangle, and setting the viewport and clipping volume to scale images to match the window size. We’ve also discussed the various OpenGL data types, and the headers and libraries required to build programs that use OpenGL.

The Auxiliary library contains many other functions to handle keyboard and mouse input as well. Microsoft’s implementation of the Aux library contains Windows-specific functions that enable access to window handles and device contexts. You are encouraged to explore the upcoming reference section of this chapter to discover other uses and features of the AUX library. You’ll also want to examine and run the other Chapter 3 samples on the CD.

Reference Section

auxIdleFunc

Purpose
Establishes a callback function for idle processing.
Include File
<glaux.h>
Syntax
void auxIdleFunc(AUXIDLEPROC func);
Description
Specifies the idle function func() to be called when no other activity is pending. Typically used for animation. When not busy rendering the current scene, the idle function changes some parameters used by the rendering function to produce the next scene.

Parameters

func
This function is prototyped as
void CALLBACK IdleFunc(void);
This is the user-defined function used for idle processing. Passing NULL as this function name will disable idle processing.
Returns
None.
Example
See BOUNCE and BOUNCE2 examples from this chapter.
See Also
auxSwapBuffers, auxMainLoop, auxReshapeFunc


Previous Table of Contents Next