From 7d074585c1de332ffe0c41cab81a8cd2bd9be6c8 Mon Sep 17 00:00:00 2001 From: fintmc Date: Sun, 20 Oct 2024 17:01:06 +0300 Subject: [PATCH] resize framebuffer textures --- ScuffedMinecraft/src/Application.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ScuffedMinecraft/src/Application.cpp b/ScuffedMinecraft/src/Application.cpp index 953a117..13d247e 100644 --- a/ScuffedMinecraft/src/Application.cpp +++ b/ScuffedMinecraft/src/Application.cpp @@ -41,6 +41,9 @@ float windowY = 1080; Camera camera; +GLuint framebufferTexture; +GLuint depthTexture; + // Window options #define VSYNC 1 // 0 for off, 1 for on @@ -120,7 +123,6 @@ int main() glGenFramebuffers(1, &FBO); glBindFramebuffer(GL_FRAMEBUFFER, FBO); - unsigned int framebufferTexture; glGenTextures(1, &framebufferTexture); glBindTexture(GL_TEXTURE_2D, framebufferTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, windowX, windowY, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); @@ -130,7 +132,6 @@ int main() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, framebufferTexture, 0); - unsigned int depthTexture; glGenTextures(1, &depthTexture); glBindTexture(GL_TEXTURE_2D, depthTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, windowX, windowY, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); @@ -220,7 +221,7 @@ int main() highestFps = fps; fpsCount++; std::chrono::steady_clock::time_point currentTimePoint = std::chrono::steady_clock::now(); - if (std::chrono::duration_cast(currentTimePoint - fpsStartTime).count() > 1000) + if (std::chrono::duration_cast(currentTimePoint - fpsStartTime).count() >= 1) { avgFps = fpsCount; lowestFps = -1; @@ -345,6 +346,14 @@ void framebufferSizeCallback(GLFWwindow* window, int width, int height) windowX = width; windowY = height; glViewport(0, 0, width, height); + + // resize framebuffer texture + glBindTexture(GL_TEXTURE_2D, framebufferTexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, windowX, windowY, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + + // resize framebuffer depth texture + glBindTexture(GL_TEXTURE_2D, depthTexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, windowX, windowY, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL); } void processInput(GLFWwindow* window)