Pro OpenGL ES for iOS

(singke) #1

172 CHAPTER 6: Will It Blend?^


used, with an increasingly smaller proportion reserved for the destination color. So as
the alpha approaches 1.0, the greater the amount of the source color that is copied to
the frame buffer, replacing the destination color.

Note In these examples, normalized color values are used because they make it much easier
to follow the process instead of using unsigned bytes, which would express the colors from 0
to 255.

Now we can examine that in the next example. To set up the blending functions
described earlier, you would use the following call:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA are the blending factors described earlier.
And remember that the first parameter is the source’s blending, the object being written
currently. Place that line immediately after where you enable blending. And to the red
colors, compile and run. Do you see Figure 6-2?

Figure 6-2. The red square has an alpha of .5, and the blue has an alpha of 1.0.
Free download pdf