CHAPTER 5: Textures (^163)
m_Pos[0]=0.0;
m_Pos[1]=0.0;
m_Pos[2]=0.0;
return self;
}
So, here is what’s happening:
A file name for the image is added to the end of the parameter list in
line 1. Remember to add it also to init’s declaration in Planet.h.
In line 2, the texture is created and GLKTextureInfo is returned.
In lines 3ff, the coordinates for the texture are allocated.
Starting at line 4, calculate the texture coordinates. Because the
sphere has x slices and y stacks and the coordinate space goes only
from 0 to 1, we need to advance each value by increments of
1/m_slices for s and 1/m_stacks for t. Notice that this covers two pairs
of coordinates, one above the other, matching the layout of the
triangle strips that also produces stacked pairs of coordinates.
In line 5, advance the pointer to the coordinate array to hold the next
set of values.
And finally, line 6 ties up some loose threads in preparation for going
to the next stack in the loop.
Next, update Planet.h by adding the following to the interface:
#import <GLKit/GLKit.h>
Also add the following:
GLKTextureInfo m_TextureInfo;
GLfloat m_TexCoordsData;
Copy over the loadTexture() method from the first example to the planet object, and
modify the header as needed. Feel free to remove the mipmap support if you like, but
there’s no harm in leaving it in; it’s just not essential for this exercise.
For an earth texture, note that this will wrap around the entire sphere model, so not just
any image will do; as such, it should resemble Figure 5-21. You can get the one I use for
this exercise, which is available from the Apress website. Or you might want to check
NASA first at http://maps.jpl.nasa.gov/.
singke
(singke)
#1