How to do it...

To create the framebuffer object that contains our g-buffer(s) use the following code:

void createGBufTex(GLenum texUnit, GLenum format, GLuint &texid ) { glActiveTexture(texUnit); glGenTextures(1, &texid); glBindTexture(GL_TEXTURE_2D, texid); glTexStorage2D(GL_TEXTURE_2D,1,format,width,height); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } ... GLuint depthBuf, posTex, normTex, colorTex; // Create and bind the FBO glGenFramebuffers(1, &deferredFBO); glBindFramebuffer(GL_FRAMEBUFFER, deferredFBO); // The depth buffer glGenRenderbuffers(1, &depthBuf); glBindRenderbuffer(GL_RENDERBUFFER, depthBuf); glRenderbufferStorage(GL_RENDERBUFFER, ...

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.