Pro OpenGL ES for iOS

(singke) #1

190 CHAPTER 6: Will It Blend?^


Figure 6-12. On the left, GL_ADD was used, GL_BLEND was added for the center, and GL_DECAL was added on
the right.

One further task would be to animate the second texture. Add the following to
drawInRect():
for(i=0;i<8;i++)
{
textureCoords2[i]+=.01;
}
Then make a duplicate of the original textureCoords array, and name it
textureCoords2. The latter coordinates are specific to the second texture, so modify the
second call to glTexCoordPointer() to use the new data. And finally, declare the index i
somewhere. You should see texture 2 scrolling wildly on top of texture 1.
An effect like this could be used to animate rain or snow in a cartoonlike setting or a
cloud layer surrounding a planet. The latter would be cool if you had two additional
textures, one for the upper deck of clouds and one for the lower, moving at different
rates.
As mentioned, the environment parameter GL_COMBINE needs an additional family of
settings to get working, because it lets you operate on a much more precise level with
the combiner equations. If you were to do nothing more than just using GL_COMBINE, it
defaults to GL_MODULATE, so you’d see no difference between the two. Using Arg0 and
Arg1 means the input sources are set up by using something like the following line,
where GL_SOURCE0_RGB is the argument 0 or Arg0, referenced in Table 6-3:
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
Free download pdf