Pro OpenGL ES for iOS

(singke) #1

64 CHAPTER 3: Building a 3D World^


Figure 3-7. The first triangle fan shares vertex 1 as the common vertex.

Stitching It All Together


Now the rendering code must be modified to handle the new data. Listing 3-4 shows the
rest of the drawInRect() method, right under the data definitions given in Listing 3-3. This
will replicate much of the earlier example, complete with motion. The major difference is
to be found in two calls to glDrawArray() because the cube is in two pieces, one each
for of the three faces or six triangles that define the two triangle fans.

Note You’ll note that many of the OpenGL ES calls end in an f, such as glScalef(),
glRotatef(), and so on. The f means that the parameters passed are floats, or GLfloat.
The only other parameter types in OpenGL ES are fixed-point values, so glScale would now
be glScalex(). Fixed point was useful for the older and slower devices, but with more
current hardware, Apple recommends staying with floats.

The obsolete lines from the previous example have been commented out but left in
place to more clearly show the differences.
Listing 3-4. The rest of the drawInRect method for the Bouncy Cube

static GLfloat transY = 0.0;
static GLfloat z=-2.0; //1

glClearColor(0.5, 0.5, 0.5, 1.0); //2
glClear(GL_COLOR_BUFFER_BIT);
Free download pdf