Pro OpenGL ES for iOS

(singke) #1

CHAPTER 7: Well-Rendered Miscellany (^207)
„ Line 4 adds a small rotation for some extra dynamic goodness.
„ glDrawArray() at line 5 does just what it always does, but because the
new FBO is bound to the system, its writes are redirected to that FBO
instead of the main screen.
„ Lines 6ff switch us over to the main FBO we’ve always used before.
glLoadIdentity() erases any built-up transformations for the subview.
„ glBindTexture() in line 7 is the heart of the magic. Instead of binding
a ‘‘normal’’ texture as was done to the secondary FBO right after line
3, we now bind the FBO itself via its access texture. Anywhere
textures can be used, our special FBO-texture can also be used.
„ Notice that glClearColor in line 8 clears the background to red, while
the secondary FBO shown earlier used blue. It’s all the more blindingly
nauseating to make the different objects stand out.
„ Line 9 uses the new set of vertices. The original set drew a square for
the textured block, but the new set draws a rectangle with the
proportions of the normal screen so that it looks like a tiny and
hyperactive version of the former. This is followed by the second
glDrawArrays(), incrementing the rotation and translation values.
You should be able to run it and see it in all of its gaudy glory. If you intend to stare at it
for an extended period of time, your doctor’s permission will be necessary. Figure 7-1
(left) is the result.
Now, it’s time to tweak. Put a second rotation of the main FBO this time around. Add it
right before the second glTranslation() call, rotating in the same direction, and you
should see Figure 7-1 (center). And what would you do to see Figure 7-1 (right)?

Free download pdf