Implementing a mirror with render-to-texture using FBO
We will now use the FBO to render a mirror object on the screen. In a typical offscreen rendering OpenGL application, we set up the FBO first, by calling the glGenFramebuffers
function and passing it the number of FBOs desired. The second parameter stores the returned identifier. After the FBO object is generated, it has to be bound to the GL_FRAMEBUFFER
, GL_DRAW_FRAMEBUFFER,
or GL_READ_FRAMEBUFFER
target. Following this call, the texture to be bound to the FBOs color attachment is attached by calling the glFramebufferTexture2D
function.
There can be more than one color attachment on an FBO. The maximum number of color attachments supported on any GPU can be queried using the GL_MAX_COLOR_ATTACHMENTS
field. The type and dimension of the texture has to be specified and it is not necessary to have the same size as the screen. However, all color attachments on the FBO must have the same dimensions. At any time, only a single FBO can be...