Pro OpenGL ES for iOS

(singke) #1

CHAPTER 6: Will It Blend? (^197)
Underneath where you allocate the main image, add the following:
if(bumpmapFile!=nil)
m_BumpMapInfo=[self loadTexture:bumpmapFile];
And to the header add this:
GLKTextureInfo *m_BumpMapInfo;
Exchange the initGeometry() call in your solar-system view controller for Listing 6-7:
-(void)initGeometry
{
m_Eyeposition[X_VALUE]=0.0;
m_Eyeposition[Y_VALUE]=0.0;
m_Eyeposition[Z_VALUE]=3.0;
m_Earth=[[Planet alloc] init:50 slices:50 radius:1.0 squash:1.0
textureFile:@"earth_light.png" bumpmapFile:@"earth_normal_hc.png"];
[m_Earth setPositionX:0.0 Y:0.0 Z:0.0];
}
Meanwhile, use Listing 6-8 as the new execute() method to be placed in Planet.m and
called from the bump mapping controller’s executePlanet() routine. This mainly sets
things up for the texture combiners and calls multiTextureBumpMap().
Listing 6-8. The Modified Execute in Planet.m that Calls multiTextureBumpMap() for Bump Mapping
-(bool)execute
{
glMatrixMode(GL_MODELVIEW);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_LIGHTING);
glFrontFace(GL_CW);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, m_VertexData);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_TextureInfo.name);
glTexCoordPointer(2, GL_FLOAT, 0, m_TexCoordsData);
glClientActiveTexture(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT,0,m_TexCoordsData);
glMatrixMode(GL_MODELVIEW);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, m_NormalData);

Free download pdf