Pro OpenGL ES for iOS

(singke) #1

178 CHAPTER 6: Will It Blend?^


And one final method here that might be really handy in some blending operations is
that of glColorMask(). This function lets you block one or more color channels from
being written to the destination. To see this in action, modify the red square’s colors to
be 1,1,0,1; set the two blend functions back to GL_ONE; and comment out the line
glBlendEquation(GL_FUNC_SUBTRACT);. You should see something like Figure 6-6 (left)
when run. The red square is now yellow and, when blended with blue, yields white at the
intersection. Now add the following line:
glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
The preceding line masks, or turns off, the green channel when being drawn to the
frame buffer. When run, you should see Figure 6-6 (right), which looks remarkably like
Figure 6-3. And as a matter of fact, logically they are identical.

Figure 6-6. The left one doesn’t use glColorMask, so all colors are in play, while the right one masks off the
green channel.
Free download pdf