Pro OpenGL ES for iOS

(singke) #1

CHAPTER 3: Building a 3D World (^83)
Figure 3-17. A triangle strip of six vertices
„ In line 11, the color array is generated, and as with the vertices, they
are generated in pairs. The green component is ignored for now.
„ At lines 12f, the color array pointer and vertex array pointers are
incremented.
„ And finally in line 13, we increment the blue and decrement the red.
Now that the geometry is out of the way, we need to concentrate on the execute
method. See Listing 3-7.
Listing 3-7. Rendering the Planet



  • (bool)execute
    {
    glMatrixMode(GL_MODELVIEW); //1
    glEnable(GL_CULL_FACE); //2
    glCullFace(GL_BACK); //3


glEnableClientState(GL_VERTEX_ARRAY); //4
glEnableClientState(GL_COLOR_ARRAY); //5


glVertexPointer(3, GL_FLOAT, 0, m_VertexData); //6


glColorPointer(4, GL_UNSIGNED_BYTE, 0, m_ColorData); //7
glDrawArrays(GL_TRIANGLE_STRIP, 0, (m_Slices +1)2(m_Stacks-1)+2); //8


return true;
}

Free download pdf