Basic Entity Components implementation
This commit is contained in:
49
BarinkEngine/src/Graphics/Memory/FrameBuffer.cpp
Normal file
49
BarinkEngine/src/Graphics/Memory/FrameBuffer.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include "Framebuffer.h"
|
||||
#include <iostream>
|
||||
|
||||
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, 1, 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);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColourAttachment, 0);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
// Create a depth buffer
|
||||
glGenRenderbuffers(1, &DepthAttachment);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, DepthAttachment);
|
||||
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
|
||||
|
||||
glFramebufferRenderbuffer(GL_RENDERBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthAttachment);
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user