OpenGL ES renders a scene on framebuffer; this framebuffer is called the default framebuffer. A framebuffer consist of various buffers, such as color, depth, and the stencil buffer. Frame Buffer Objects (FBO) allows you to create user-defined framebuffers, which can be used to render scenes on non-default framebuffers. The rendered scene on the nondefault framebuffer can be used as a texture to map objects. In this recipe, we will demonstrate render to texture in which a scene is rendered to a texture and this texture is mapped to a 2D plane surface; the 2D plane can be rotated in a 3D space using touch gesture events.
The detailed procedure to implement the render to texture recipe using FBO is as follows. We will reuse the Generating the polka dot pattern recipe from Chapter 6, Working with Shaders:
Create a
DemoFBO
class derived from theModel
base class and addSimpleTexture
andObjLoader
pointer objects; initialize...