Fixed Framebuffer

This commit is contained in:
MihailRis 2023-11-27 19:13:17 +03:00
parent 6fcfc7e272
commit 7b4cc8f650
2 changed files with 26 additions and 46 deletions

View File

@ -3,46 +3,24 @@
#include <GL/glew.h> #include <GL/glew.h>
#include "Texture.h" #include "Texture.h"
Framebuffer::Framebuffer(int width, int height) : width(width), height(height) { Framebuffer::Framebuffer(uint width, uint height) : width(width), height(height) {
// glGenFramebuffers(1, &fbo); glGenFramebuffers(1, &fbo);
// bind(); bind();
// GLuint tex; GLuint tex;
// glGenTextures(1, &tex); glGenTextures(1, &tex);
// // glBindTexture(GL_TEXTURE_2D, tex); glBindTexture(GL_TEXTURE_2D, tex);
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
// // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, width, height, GL_TRUE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
// glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); texture = new Texture(tex, width, height);
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, tex, 0); glGenRenderbuffers(1, &depth);
// texture = new Texture(tex, width, height); glBindRenderbuffer(GL_RENDERBUFFER, depth);
// glGenRenderbuffers(1, &depth); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
// glBindRenderbuffer(GL_RENDERBUFFER, depth); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
// glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT24, width, height); unbind();
// // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
// glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
// unbind();
// bind();
// glGenFramebuffers(1, &fbo);
// // create a multisampled color attachment texture
// unsigned int textureColorBufferMultiSampled;
// glGenTextures(1, &textureColorBufferMultiSampled);
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled);
// glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, width, height, GL_TRUE);
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, textureColorBufferMultiSampled, 0);
// // create a (also multisampled) renderbuffer object for depth and stencil attachments
// unsigned int rbo;
// glGenRenderbuffers(1, &rbo);
// glBindRenderbuffer(GL_RENDERBUFFER, rbo);
// glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, width, height);
// glBindRenderbuffer(GL_RENDERBUFFER, 0);
// glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbo);
// unbind();
} }
Framebuffer::~Framebuffer() { Framebuffer::~Framebuffer() {

View File

@ -1,16 +1,18 @@
#ifndef SRC_GRAPHICS_FRAMEBUFFER_H_ #ifndef SRC_GRAPHICS_FRAMEBUFFER_H_
#define SRC_GRAPHICS_FRAMEBUFFER_H_ #define SRC_GRAPHICS_FRAMEBUFFER_H_
#include "../typedefs.h"
class Texture; class Texture;
class Framebuffer { class Framebuffer {
unsigned int fbo; uint fbo;
unsigned int depth; uint depth;
public: public:
int width; uint width;
int height; uint height;
Texture* texture; Texture* texture;
Framebuffer(int width, int height); Framebuffer(uint width, uint height);
~Framebuffer(); ~Framebuffer();
void bind(); void bind();