Pro OpenGL ES for iOS

(singke) #1

196 CHAPTER 6: Will It Blend?^


„ Here we set up ‘‘stage 0,’’ the first of two stages. The source of the
first bit of data is specified in line 8. This says to use the texture from
the current texture unit (GL_TEXTURE0) as the source for the bump map
assigned in line 5.
„ T h e n l i n e 9 t e l l s i t t o b l e n d w i t h t h e p r e v i o u s c o l o r -----in this case,
that which was set via glColor() in line 4. For stage 0, GL_PREVIOUS
is the same as GL_PRIMARY_COLOR, because there is no previous texture
to use.
„ Now set up stage 1 in line 10 and the following line. The argument,
tex1, is the color image.
„ Now all we want to do is combine the image with the bump map,
which is what line 11 does.
Now all you have to do is to call the new method in place of multTexture() used in the
previous exercise. My source texture is selected so that you can easily see the results.
When started, the light should move from left to right and illuminate the edges of the
land masses, as shown in Figure 6-16.

Figure 6-16. Bump-mapped North America at morning, noon, and evening, respectively

Looks pretty cool, eh? But can we apply this to a spinning sphere? Give it a shot and
recycle the solar-system model from the end of the previous chapter. To make the fine
detail of the bump map more easily seen, the sun is dropped in lieu of a somewhat
larger image for the earth. So, we’ll load the bump map, move the earth to the center of
the scene, tweak the lighting, and add the combiner support.
So first off, add a new parameter to the init method of Planet.m for the bump map so
that it looks like the following line, and call it where you generate the earth object:
-(id) init:(GLint)stacks slices:(GLint)slices radius:(GLfloat)radius
squash:(GLfloat)squash textureFile:(NSString *)textureFile bumpmapFile:(NSString
*)bumpmapFile
Free download pdf