Update Framebuffer resize code
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[Window][Debug##Default]
|
||||
Pos=60,60
|
||||
Pos=-18,59
|
||||
Size=400,400
|
||||
Collapsed=0
|
||||
|
||||
@@ -9,7 +9,7 @@ Size=894,195
|
||||
Collapsed=0
|
||||
|
||||
[Window][Debug Utils]
|
||||
Pos=10,7
|
||||
Pos=-18,7
|
||||
Size=871,365
|
||||
Collapsed=0
|
||||
|
||||
|
||||
@@ -79,16 +79,15 @@ Controller::~Controller()
|
||||
ImGui::DestroyContext();
|
||||
#endif
|
||||
|
||||
delete gameWindow;
|
||||
delete gameEventHandler;
|
||||
delete camera;
|
||||
|
||||
for (auto it = shaderPrograms.begin(); it != shaderPrograms.end(); it++) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
delete pp_framebuffer;
|
||||
delete camera;
|
||||
delete menu;
|
||||
delete pp_framebuffer;
|
||||
delete gameEventHandler;
|
||||
delete gameWindow;
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
@@ -116,7 +115,7 @@ void Controller::run()
|
||||
// This is the game loop
|
||||
while (!glfwWindowShouldClose(gameWindow->getGLFWwindow())) {
|
||||
// --- Timing ---
|
||||
limit_framerate();
|
||||
//limit_framerate();
|
||||
|
||||
// --- Update game ---
|
||||
|
||||
@@ -174,7 +173,7 @@ void Controller::run()
|
||||
|
||||
// Update window size
|
||||
if (gameWindow->checkWindowWasResized()) {
|
||||
updateWindowSize(getShaderProgramByName("postProcessingProgram"));
|
||||
updateWindowSize();
|
||||
}
|
||||
|
||||
// --- Check events, handle input ---
|
||||
@@ -218,13 +217,12 @@ void Controller::error_callback(int error, const char *description)
|
||||
fprintf(stderr, "Error: %s\n", description);
|
||||
}
|
||||
|
||||
void Controller::updateWindowSize(ShaderProgram *pp_program)
|
||||
void Controller::updateWindowSize()
|
||||
{
|
||||
camera->updateAspectRatio(gameWindow->getWindowAspectRatio());
|
||||
gameEventHandler->setFirstMouseInput(1);
|
||||
|
||||
delete pp_framebuffer;
|
||||
pp_framebuffer = new Framebuffer(gameWindow->getWindowWidth(), gameWindow->getWindowHeight(), pp_program);
|
||||
pp_framebuffer->changeDimensions(gameWindow->getWindowWidth(), gameWindow->getWindowHeight());
|
||||
}
|
||||
|
||||
void Controller::updateExposure(ShaderProgram *shaderProgram)
|
||||
@@ -276,7 +274,7 @@ void Controller::renderImGui(World &world, PointLight *pointLight, glm::vec3 *li
|
||||
ImGui::Checkbox("Rotate Object", rotateEntity);
|
||||
|
||||
Entity *mainObject = world.getEntityById(0);
|
||||
//mainObject->setPosition(glm::vec3(translation[0], translation[1], translation[2]));
|
||||
mainObject->setPosition(glm::vec3(translation[0], translation[1], translation[2]));
|
||||
if (!*rotateEntity) {
|
||||
//mainObject->setRotation(glm::vec3(0.f, 1.0f, 0.f), rotation);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public:
|
||||
private:
|
||||
void limit_framerate();
|
||||
|
||||
void updateWindowSize(ShaderProgram *pp_program);
|
||||
void updateWindowSize();
|
||||
void updateExposure(ShaderProgram *shaderProgram);
|
||||
|
||||
ShaderProgram* getShaderProgramByName(const char *name);
|
||||
|
||||
@@ -3,30 +3,12 @@
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
|
||||
Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram)
|
||||
Framebuffer::Framebuffer(uint32_t width, uint32_t height, ShaderProgram *shaderProgram) :
|
||||
shaderProgram(shaderProgram)
|
||||
{
|
||||
this->shaderProgram = shaderProgram;
|
||||
|
||||
glGenFramebuffers(1, &FBO);
|
||||
|
||||
glGenTextures(2, textures);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
bind();
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textures[1], 0);
|
||||
unbind();
|
||||
generateTextutes(width, height);
|
||||
}
|
||||
|
||||
Framebuffer::~Framebuffer()
|
||||
@@ -73,6 +55,38 @@ void Framebuffer::render(GLuint customTextureId)
|
||||
shaderProgram->unbind();
|
||||
}
|
||||
|
||||
void Framebuffer::changeDimensions(uint32_t width, uint32_t height)
|
||||
{
|
||||
// Delete old textures
|
||||
glDeleteTextures(2, textures);
|
||||
|
||||
generateTextutes(width, height);
|
||||
}
|
||||
|
||||
void Framebuffer::generateTextutes(uint32_t width, uint32_t height)
|
||||
{
|
||||
// Create new textures
|
||||
glGenTextures(2, textures);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[0]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, textures[1]);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
bind();
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, textures[1], 0);
|
||||
unbind();
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::setExposureCorrection(bool exposureCorrection)
|
||||
{
|
||||
shaderProgram->bind();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
class Framebuffer
|
||||
{
|
||||
public:
|
||||
Framebuffer(uint32_t width, uint32_t height, ShaderProgram *ShaderProgram);
|
||||
Framebuffer(uint32_t width, uint32_t height, ShaderProgram* shaderProgram);
|
||||
~Framebuffer();
|
||||
|
||||
void bind();
|
||||
@@ -15,6 +15,8 @@ public:
|
||||
|
||||
void render(GLuint customTextureId = 0);
|
||||
|
||||
void changeDimensions(uint32_t width, uint32_t height);
|
||||
|
||||
GLuint getTextureId()
|
||||
{
|
||||
return textures[0];
|
||||
@@ -22,6 +24,8 @@ public:
|
||||
void setExposureCorrection(bool exposureCorrection);
|
||||
|
||||
private:
|
||||
void generateTextutes(uint32_t width, uint32_t height);
|
||||
|
||||
GLuint FBO;
|
||||
GLuint textures[2];
|
||||
|
||||
|
||||
@@ -37,8 +37,10 @@ std::vector<Model*> JsonParser::getModels()
|
||||
std::string model_name = modelsJson[index]["unique_name"].asString();
|
||||
std::string model_path = modelsJson[index]["path"].asString();
|
||||
Model *current_model = new Model(model_name, model_path);
|
||||
temp_models.push_back(current_model);
|
||||
std::cout << "Loaded Model \"" << model_name << "\" from \"" << model_path << "\"" << std::endl;
|
||||
if(current_model) {
|
||||
temp_models.push_back(current_model);
|
||||
std::cout << "Loaded Model \"" << model_name << "\" from \"" << model_path << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return temp_models;
|
||||
|
||||
Reference in New Issue
Block a user