diff --git a/res/shaders/postprocessing.frag b/res/shaders/postprocessing.frag index 7fc931b..6dd7047 100644 --- a/res/shaders/postprocessing.frag +++ b/res/shaders/postprocessing.frag @@ -1,6 +1,6 @@ #version 330 core -const float GAMMA = 2.0f; +const float GAMMA = 2.2f; layout(location = 0) out vec4 f_color; diff --git a/src/Controller.cpp b/src/Controller.cpp index a58e76c..ffa77e1 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -115,7 +115,7 @@ void Controller::run() { camera->translate(glm::vec3(0.0f, 1.5f, 5.0f)); - pp_framebuffer = new Framebuffer(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT); + pp_framebuffer = new Framebuffer(INIT_WINDOW_WIDTH, INIT_WINDOW_HEIGHT, &postProcessingProgram); // This is the game loop while(!glfwWindowShouldClose(gameWindow->getGLFWwindow())) { @@ -150,22 +150,7 @@ void Controller::run() { world.draw(camera->getViewProj(), camera->getPosition()); pp_framebuffer->unbind(); - postProcessingProgram.bind(); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, pp_framebuffer->getTextureId()); - GLint location = glGetUniformLocation(postProcessingProgram.getShaderProgramId(), "u_texture"); - glUniform1i(location, 0); - // Disable wireframe mode - GLint wireframe; - glGetIntegerv(GL_POLYGON_MODE, &wireframe); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - GLuint temp_vao; - glGenVertexArrays(1, &temp_vao); - glBindVertexArray(temp_vao); - glDrawArrays(GL_TRIANGLES, 0, 3); - glBindVertexArray(0); - glPolygonMode(GL_FRONT_AND_BACK, wireframe); - postProcessingProgram.unbind(); + pp_framebuffer->render(); #ifdef _DEBUG renderImGui(world.getEntities(), &world.getPointLights()[0], &lightColor, &rotateLightSource); @@ -175,7 +160,7 @@ void Controller::run() { // Update window size if(gameWindow->checkWindowWasResized()) - updateWindowSize(); + updateWindowSize(&postProcessingProgram); // Check events, handle input gameEventHandler->handleEvents(); @@ -216,12 +201,12 @@ void Controller::error_callback(int error, const char* description) { fprintf(stderr, "Error: %s\n", description); } -void Controller::updateWindowSize() { +void Controller::updateWindowSize(ShaderProgram *pp_program) { camera->updateAspectRatio(gameWindow->getWindowAspectRatio()); gameEventHandler->setFirstMouseInput(1); delete pp_framebuffer; - pp_framebuffer = new Framebuffer(gameWindow->getWindowWidth(), gameWindow->getWindowHeight()); + pp_framebuffer = new Framebuffer(gameWindow->getWindowWidth(), gameWindow->getWindowHeight(), pp_program); } #ifdef _DEBUG diff --git a/src/Controller.h b/src/Controller.h index f0d5aa3..b9c5760 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -26,7 +26,7 @@ private: void limit_framerate(); - void updateWindowSize(); + void updateWindowSize(ShaderProgram *pp_program); void renderImGui(std::vector *entites, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateLightSource); diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index a84a091..1cd48d0 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -2,7 +2,9 @@ #include -Framebuffer::Framebuffer(uint32_t width, uint32_t height) { +Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram) { + + this->shaderProgram = shaderProgram; glGenFramebuffers(1, &FBO); @@ -37,3 +39,19 @@ void Framebuffer::bind() { void Framebuffer::unbind() { glBindFramebuffer(GL_FRAMEBUFFER, 0); } + +void Framebuffer::render() { + shaderProgram->bind(); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, getTextureId()); + GLint location = glGetUniformLocation(shaderProgram->getShaderProgramId(), "u_texture"); + glUniform1i(location, 0); + + // A VAO is necessary although no data is stored in it + GLuint temp_vao; + glGenVertexArrays(1, &temp_vao); + glBindVertexArray(temp_vao); + glDrawArrays(GL_TRIANGLES, 0, 3); + glBindVertexArray(0); + shaderProgram->unbind(); +} diff --git a/src/Framebuffer.h b/src/Framebuffer.h index bef9ff5..cb2bb78 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -1,17 +1,20 @@ #pragma once #include +#include "ShaderProgram.h" class Framebuffer { public: - Framebuffer(uint32_t width, uint32_t height); + Framebuffer(uint32_t width, uint32_t height, ShaderProgram *ShaderProgram); ~Framebuffer(); void bind(); void unbind(); + void render(); + GLuint getTextureId() { return textures[0]; } @@ -21,4 +24,6 @@ private: GLuint FBO; GLuint textures[2]; + ShaderProgram *shaderProgram; + }; \ No newline at end of file diff --git a/src/World.cpp b/src/World.cpp index edf570e..2eeaf6c 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -20,7 +20,7 @@ World::World(ShaderProgram *shaderProgram) // This will be removed in future when gloss maps are implemented shaderProgram->bind(); - shaderProgram->setUniform("u_material.shininess", 64.0f); + shaderProgram->setUniform("u_material.shininess", 100.0f); shaderProgram->unbind(); }