Pro OpenGL ES for iOS

(singke) #1

180 CHAPTER 6: Will It Blend?^


Figure 6-7. No blending (left), GL_ONE blending (center), alpha blending (right), respectively

Texture Blending

Now, with fear and trembling, we can approach the blending of textures. Initially this
seems much like the earlier alpha blending, but all sorts of interesting things can be
done by using multitexturing.
First let’s rework the earlier code to support two textures at once and do vertex
blending. Listing 6-3 merges some of the code from Chapter 5 with the framework from
this chapter’s examples.
Listing 6-3. The drawInRect() Method Rejiggered to Support Two Textured Squares


  • (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
    {


static const GLfloat squareVertices[] =
{
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
-0.5, 0.5, 0.0,
0.5, 0.5, 0.0
};
Free download pdf