Create Framebuffer render function
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#version 330 core
|
||||
|
||||
const float GAMMA = 2.0f;
|
||||
const float GAMMA = 2.2f;
|
||||
|
||||
layout(location = 0) out vec4 f_color;
|
||||
|
||||
|
||||
@@ -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,17 +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);
|
||||
GLuint temp_vao;
|
||||
glGenVertexArrays(1, &temp_vao);
|
||||
glBindVertexArray(temp_vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glBindVertexArray(0);
|
||||
postProcessingProgram.unbind();
|
||||
pp_framebuffer->render();
|
||||
|
||||
#ifdef _DEBUG
|
||||
renderImGui(world.getEntities(), &world.getPointLights()[0], &lightColor, &rotateLightSource);
|
||||
@@ -170,7 +160,7 @@ void Controller::run() {
|
||||
|
||||
// Update window size
|
||||
if(gameWindow->checkWindowWasResized())
|
||||
updateWindowSize();
|
||||
updateWindowSize(&postProcessingProgram);
|
||||
|
||||
// Check events, handle input
|
||||
gameEventHandler->handleEvents();
|
||||
@@ -211,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
|
||||
|
||||
@@ -26,7 +26,7 @@ private:
|
||||
|
||||
void limit_framerate();
|
||||
|
||||
void updateWindowSize();
|
||||
void updateWindowSize(ShaderProgram *pp_program);
|
||||
|
||||
void renderImGui(std::vector<Entity> *entites, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateLightSource);
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <glad/glad.h>
|
||||
#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;
|
||||
|
||||
};
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user