void FrameBufferObject::setSize(unsigned int width, unsigned height) { if (initialized) { this->width = width; this->height = height; if(enableDepth) initDepthBuffer(); if(enableColor) initColorBuffer(); } }
void fbo::initFrameBuffer(void){ initDepthBuffer(); // Initialize our frame buffer depth buffer initTextureBuffer(); // Initialize our frame buffer texture glGenFramebuffersEXT(1, &id); // Generate one frame buffer and store the ID in fbo glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, id); // Bind our frame buffer glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture_id, 0); // Attach the texture fbo_texture to the color buffer in our frame buffer glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_id); // Attach the depth buffer fbo_depth to our frame buffer GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); // Check that status of our generated frame buffer if (status != GL_FRAMEBUFFER_COMPLETE_EXT) // If the frame buffer does not report back as complete { std::cout << "Couldn't create frame buffer" << std::endl; // Output an error to the console } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // Unbind our frame buffer }
void FrameBufferObject::init(unsigned int width, unsigned height) { if (!initialized) { this->width = width; this->height = height; glGenFramebuffersEXT(1, &id); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, id); if(enableDepth) { createDepthBuffer(); initDepthBuffer(); //choice between rendering depth into a texture or a renderbuffer if(depthTexture) glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, depthTextureID, 0); else glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthTextureID); } if(enableColor) { createColorBuffer(); initColorBuffer(); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorTextureID, 0); } glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_defaultWindowFramebufferID); if(enableColor) { glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK);; } #ifdef _DEBUG checkFBO(); #endif initialized=true; glDisable(GL_TEXTURE_2D); } else setSize(width, height); }