|How To…||Functions You’ll Use|
|Draw points, lines, and shapes||glBegin/glEnd/glVertex|
|Set shape outlines to wireframe or solid objects||glPolygonMode|
|Set point sizes for drawing||glPointSize|
|Set line drawing width||glLineWidth|
|Perform hidden surface removal||glCullFace|
|Set patterns for broken lines||glLineStipple|
|Set polygon fill patterns||glPolygonStipple|
If you’ve ever had a chemistry class (and probably even if you haven’t), you know that all matter is made up of atoms, and that all atoms consist of only three things: protons, neutrons, and electrons. All the materials and substances you have ever come into contact with—from the petals of a rose to the sand on the beach—are just different arrangements of these three fundamental building blocks. Although this is a little oversimplified for most anyone beyond the third or fourth grade, it demonstrates a powerful principle: With just a few simple building blocks, you can create highly complex and beautiful structures.
The connection is fairly obvious. Objects and scenes that you create with OpenGL are also made up of smaller, simpler shapes, arranged and combined in various and unique ways. In this chapter we will explore these building blocks of 3D objects, called primitives. All primitives in OpenGL are one- or two-dimensional objects, ranging from single points to lines and complex polygons. In this chapter you will learn everything you need to know in order to draw objects in three dimensions from these simpler shapes.
When you first learned to draw any kind of graphics on any computer system, you usually started with pixels. A pixel is the smallest element on your computer monitor, and on color systems that pixel can be any one of many available colors. This is computer graphics at its simplest: Draw a point somewhere on the screen, and make it a specific color. Then build on this simple concept, using your favorite computer language to produce lines, polygons, circles, and other shapes and graphics. Perhaps even a GUI…
With OpenGL, however, drawing on the computer screen is fundamentally different. You’re not concerned with physical screen coordinates and pixels, but rather positional coordinates in your viewing volume. You let OpenGL worry about how to get your points, lines, and everything else translated from your established 3D space to the 2D image made by your computer screen.
This chapter and the next cover the most fundamental concepts of OpenGL or any 3D graphics toolkit. In the upcoming chapter, we’ll go into substantial detail about how this transformation from 3D space to the 2D landscape of your computer monitor takes place, as well as how to manipulate (rotate, translate, and scale) your objects. For now, we shall take this ability for granted in order to focus on plotting and drawing in a 3D coordinate system. This may seem backwards, but if you first know how to draw something, and then worry about all the ways to manipulate your drawings, the material coming up in Chapter 7 will be more interesting and easier to learn. Once you have a solid understanding of graphics primitives and coordinate transformations, you will be able to quickly master any 3D graphics language or API.
Figure 6-1 shows a simple viewing volume that we will use for the examples in this chapter. The area enclosed by this volume is a Cartesian coordinate space that ranges from –100 to +100 on all three axes, x, y, and z. (For a review of Cartesian coordinates, see Chapter 2.) Think of this viewing volume as your three-dimensional canvas on which you will be drawing with OpenGL commands and functions.
Figure 6-1 Cartesian viewing volume measuring 100 x 100 x 100
|Previous||Table of Contents||Next|