#include "Framebuffer.h" #include Framebuffer::Framebuffer() { glGenFramebuffers(1, &Id); glBindFramebuffer(GL_FRAMEBUFFER, Id); // Create a colour texture! glGenTextures(1, &ColourAttachment); glBindTexture(GL_TEXTURE_2D, ColourAttachment); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColourAttachment, 0); // Create a depth buffer glGenTextures(1, &DepthAttachment); glBindTexture(GL_TEXTURE_2D, DepthAttachment); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, 800, 600, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DepthAttachment, 0); /* * // Render buffer glGenRenderbuffers(1, &DepthAttachment); glBindRenderbuffer(GL_RENDERBUFFER, DepthAttachment); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600); glBindRenderbuffer(GL_RENDERBUFFER, 0); glFramebufferRenderbuffer(GL_RENDERBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthAttachment); */ if (!glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) { std::cout << "Framebuffer is incomplete!" << std::endl; } else { std::cout << "Framebuffer is complete!" << std::endl; } glBindFramebuffer(GL_FRAMEBUFFER, 0); } Framebuffer::~Framebuffer() { glDeleteTextures(1, &ColourAttachment); glDeleteRenderbuffers(1, &DepthAttachment); glDeleteFramebuffers(1, &Id); }