Pro OpenGL ES for iOS

(singke) #1

CHAPTER 6: Will It Blend? (^175)
Figure 6-4. The left is drawn with blue first (left), while the one on the right is drawn with red first (right).
The intersections are slightly different colors. This shows one of the mystifying gotchas
in OpenGL: like with most 3D frameworks, the blending will be slightly different
depending on the order of the faces and colors when rendered. In this case, it is actually
quite simple to figure out what’s going on. In Figure 6-4 (left), the blue square is drawn
first with an alpha of .5. So, even though the blue color triplet is defined as 0,0,1, the
alpha value will knock that down to 0,0,.5 while it is written to the frame buffer. Now add
the red square with similar properties. Naturally, the red will write to the black part of the
frame buffer in the same manner as the blue, so the final value will be .5,0,0. But note
what happens when red writes on top of the blue. Since the blue is already at half of its
intensity, the blending function will cut that down even further, to .25, as a result of the
destination part of the blending function, (1.0-Source alpha)*blue+destination, or (1.0-
.5).5+0, or .25. The final color is then .5,0,.25. With the lower intensity of the blue, it
contributes less to the composite color, leaving red to dominate. Now in Figure 6-4
(right), the order is reversed, so the blue dominates with a final color of .25,0,.5.

Free download pdf