Skip to content

Commit a8d43bc

Browse files
committed
Added framebuffer
1 parent 06d0914 commit a8d43bc

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

framebuffer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
#include "defines.h"
44

5-
struct FrameBuffer {
5+
struct Framebuffer {
66
void create(uint32 width, uint32 height) {
77
glGenFramebuffers(1, &fbo);
88

9-
unsigned int textures[2];
109
glGenTextures(2, textures);
1110

1211
glBindTexture(GL_TEXTURE_2D, textures[0]);
@@ -40,4 +39,5 @@ struct FrameBuffer {
4039

4140
private:
4241
GLuint fbo;
42+
GLuint textures[2];
4343
};

main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void _GLGetError(const char* file, int line, const char* call) {
4646
#include "floating_camera.h"
4747
#include "mesh.h"
4848
#include "font.h"
49+
#include "framebuffer.h"
4950

5051
void openGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam) {
5152
std::cout << "[OpenGL Error] " << message << std::endl;
@@ -159,6 +160,11 @@ int main(int argc, char** argv) {
159160
GLCALL(glEnable(GL_CULL_FACE));
160161
GLCALL(glEnable(GL_DEPTH_TEST));
161162

163+
Framebuffer framebuffer;
164+
int w, h;
165+
SDL_GetWindowSize(window, &w, &h);
166+
framebuffer.create(w, h);
167+
162168
while(!close) {
163169
SDL_Event event;
164170
while(SDL_PollEvent(&event)) {
@@ -240,6 +246,8 @@ int main(int argc, char** argv) {
240246
}
241247

242248
camera.update();
249+
250+
framebuffer.bind();
243251
shader.bind();
244252
model = glm::rotate(model, 1.0f*delta, glm::vec3(0, 1, 0));
245253
modelViewProj = camera.getViewProj() * model;
@@ -259,6 +267,7 @@ int main(int argc, char** argv) {
259267
GLCALL(glUniformMatrix4fv(invModelViewLocation, 1, GL_FALSE, &invModelView[0][0]));
260268
monkey.render();
261269
shader.unbind();
270+
framebuffer.unbind();
262271

263272
fontShader.bind();
264273

@@ -289,5 +298,7 @@ int main(int argc, char** argv) {
289298
lastCounter = endCounter;
290299
}
291300

301+
framebuffer.destroy();
302+
292303
return 0;
293304
}

0 commit comments

Comments
 (0)