From 0cea9c894eb514c70ff7c8edd0ccfa59c1f07a1a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 18 Nov 2022 21:41:15 +0000 Subject: Save size of output in SceneRender and set viewport accordingly --- ui/gameMainWindow.cpp | 2 +- ui/sceneRenderer.cpp | 10 ++++++---- ui/sceneRenderer.h | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index e49f4a9..c31265a 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -29,7 +29,7 @@ public: }; GameMainWindow::GameMainWindow(size_t w, size_t h) : - Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {size, 0} + Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0} { uiComponents.create(glm::vec2 {-1150, -1150}); auto gms = uiComponents.create(&camera, glm::vec2 {w, h}); diff --git a/ui/sceneRenderer.cpp b/ui/sceneRenderer.cpp index 6986fb6..6a68ac6 100644 --- a/ui/sceneRenderer.cpp +++ b/ui/sceneRenderer.cpp @@ -11,8 +11,8 @@ static constexpr std::array displayVAOdata {{ {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f, 0.0f}, }}; -SceneRenderer::SceneRenderer(glm::ivec2 size, GLuint o) : - camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, ratio(size), 0.1F, 10000.0F}, output {o}, +SceneRenderer::SceneRenderer(glm::ivec2 s, GLuint o) : + camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, ratio(s), 0.1F, 10000.0F}, size {s}, output {o}, lighting {lightingShader_vs, lightingShader_fs} { glBindVertexArray(displayVAO); @@ -24,7 +24,7 @@ SceneRenderer::SceneRenderer(glm::ivec2 size, GLuint o) : glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); const auto configuregdata - = [size](const GLuint data, const GLint format, const GLenum type, const GLenum attachment) { + = [this](const GLuint data, const GLint format, const GLenum type, const GLenum attachment) { glBindTexture(GL_TEXTURE_2D, data); glTexImage2D(GL_TEXTURE_2D, 0, format, size.x, size.y, 0, GL_RGBA, type, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -53,6 +53,8 @@ void SceneRenderer::render(std::function content) const { shader.setView(camera.GetViewProjection()); + glViewport(0, 0, size.x, size.y); + // Geometry pass glEnable(GL_BLEND); glEnable(GL_CULL_FACE); @@ -62,9 +64,9 @@ SceneRenderer::render(std::function content) const glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); content(shader); - glBindFramebuffer(GL_FRAMEBUFFER, output); // Lighting pass + glBindFramebuffer(GL_FRAMEBUFFER, output); glDisable(GL_BLEND); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glActiveTexture(GL_TEXTURE0); diff --git a/ui/sceneRenderer.h b/ui/sceneRenderer.h index 50feaa2..c06fa83 100644 --- a/ui/sceneRenderer.h +++ b/ui/sceneRenderer.h @@ -16,6 +16,7 @@ public: Camera camera; private: + glm::ivec2 size; GLuint output; glFrameBuffer gBuffer; glTexture gPosition, gNormal, gAlbedoSpec; -- cgit v1.2.3