How to do it...

To render to a texture and then apply that texture to a scene in a second pass, use the following steps:

  1. Within the main OpenGL program, use the following code to set up the framebuffer object:
GLuint fboHandle; // The handle to the FBO // Generate and bind the framebuffer glGenFramebuffers(1, &fboHandle); glBindFramebuffer(GL_FRAMEBUFFER, fboHandle); // Create the texture object GLuint renderTex; glGenTextures(1, &renderTex); glActiveTexture(GL_TEXTURE0); // Use texture unit 0 glBindTexture(GL_TEXTURE_2D, renderTex); glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, 512, 512); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Bind the texture ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.