Pro OpenGL ES for iOS

(singke) #1

62 CHAPTER 3: Building a 3D World^


Figure 3-5. Notice the various axes: X going right, Y is up, and Z is toward the viewer.

Some new data is now needed to tell OpenGL in what order the vertices are to be used.
With the square it was a no-brainer to order, or sequence, the data by hand so that the
four vertices could represent the two triangles. The cube makes this considerably more
complicated. We could have defined each of the six faces of the cube by separate
vertex arrays, but that wouldn’t scale well for more complex objects. And it would be
less efficient than having to shove six sets of data through the graphics hardware. Thus,
keeping all the data in a single array is the most efficient from both a memory and a
performance standpoint. So, how do we tell OpenGL the layout of the data? In this case,
we’ll use the drawing mode called triangle fans, as shown in Figure 3-6. A triangle fan is
a set of triangles that share a common vertex.

Figure 3-6. A triangle fan has one common point with all triangles.

Data can be stored and presented to OpenGL ES in many different ways. One format
may be faster but uses more memory, while another may use less memory but at the
cost of a little extra overhead. If you were to import data from one of the 3D files,
Free download pdf