Pro OpenGL ES for iOS by Mike Smithwick

Pro OpenGL ES for iOS by Mike Smithwick

Author:Mike Smithwick
Language: eng
Format: epub, pdf
Publisher: Apress®
Published: 2011-12-11T16:00:00+00:00


static const GLfloat squareColorsRGBA[] =

{

1.0, 0, 0, 1.0,

0, 1.0, 0, 1.0,

0, 0, 1.0, 1.0,

1.0, 1.0, 1.0, 1.0,

};

Assign the first color array to the first square (which has been the blue one up until now), and assign the second to the former red square. And don't forget to enable the use of the color array. You should be familiar enough now to know what to do. Also, notice that the arrays are now normalized as a bunch of GLfloats as opposed to the previously used unsigned bytes, so you'll have to tweak the calls to glColorPointer(). The solution is left up to the reader (I've always wanted to say that). With the blending disabled, you should see Figure 6-7 (left), and when enabled using the traditional function for transparency, Figure 6-7 (center) should be the result. What? It isn't? You say it still looks like the first figure? Why would that be?

Look back at the color arrays. Notice how the last value in each row, alpha, is at its maximum of 1.0. Remember that with this blending mode, any of the destination values are multiplied by: (1.0 – source alpha), or rather, 0.0, so that the source color reigns supreme as you saw in a previous example. One solution to seeing some real transparency would be to use the following:

glBlendFunc(GL_ONE, GL_ONE);

This works because it ditches the alpha channel altogether. If you want alpha with the “standard” function, merely change the 1.0 values to something else, such as .5. And the result is Figure 6-7 (right).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.