Implementing offscreen rendering in OpenGL
Before we can proceed with generic postprocessing effects, let's implement some basic OpenGL machinery for offscreen rendering using framebuffer objects. We will rely on this code throughout the remaining chapters of this book to implement various rendering and postprocessing techniques.
Getting ready
The code for this recipe is located in the shared/glFramework/GLFramebuffer.h
. file. It would be helpful to quickly go through the entire code before reading the rest of this recipe.
How to do it…
Let's implement a simple GLFramebuffer
class to handle all the underlying OpenGL framebuffer objects' manipulations and attachments:
- Our framebuffer implementation holds the width and height dimensions of the framebuffer, its OpenGL handle, and two
GLTexture
objects, for color and depth buffers respectively. As we do not need to render into multiple render targets, having just one of each buffer is sufficient...