Pro OpenGL ES for iOS

(singke) #1

164 CHAPTER 5: Textures^


Figure 5-21. Textures typically fill out the entire frame, edge to edge. Planets use a Mercator projection (a
cylindrical map).

When you’ve found a suitable image, add it to your project and hand it off to the planet
object when allocated back in your solar system’s controller. Because you don’t need a
texture for the sun, you can just pass a nil pointer. And of course we’ll need to update
the execute() method, as shown in Listing 5-7.
Listing 5-7. Ready to handle the new texture

-(bool)execute
{
glMatrixMode(GL_MODELVIEW);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CW);

glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);

if(m_TexCoordsData!=nil)
{
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

if(m_TextureInfo!=0)
glBindTexture(GL_TEXTURE_2D, m_TextureInfo.name);

glTexCoordPointer(2, GL_FLOAT, 0, m_TexCoordsData);
}

glMatrixMode(GL_MODELVIEW);

glVertexPointer(3, GL_FLOAT, 0, m_VertexData);
glNormalPointer(GL_FLOAT, 0, m_NormalData);
Free download pdf