Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Generate and bind a new framebuffer.
- glGenFramebuffers(1, &fbo);
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
- //Generate and bind a new texture target. Then bind it to the frame buffer.
- glGenTextures(1, &colorBuffer);
- glBindTexture(GL_TEXTURE_2D, colorBuffer);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBuffer, 0);
- //Generate the space to store the depth and stencil buffers.
- glGenRenderbuffers(1, &rbo);
- glBindRenderbuffer(GL_RENDERBUFFER, rbo);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo);
- //Unbind the render buffer and texture buffer.
- glBindTexture(GL_TEXTURE_2D, 0);
- glBindRenderbuffer(GL_RENDERBUFFER, 0);
- //Make sure the buffer is correctly set up.
- GLenum status;
- if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE)
- {
- std::cout << "Frame buffer status: " << std::hex << status << std::dec << std::endl;
- std::cout << "Buffer ID's: " << fbo << " " << rbo << " " << colorBuffer << std::endl;
- std::cout << "Width and Height: " << width << " " << height << std::endl;
- assert(0 && "Could not generate frame buffer!");
- }
- glBindFramebuffer(GL_FRAMEBUFFER, 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement