From 5b854f135a4bf38ce993cc567461bf204894fb44 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 13 Nov 2022 14:43:20 +0000 Subject: Pass the output framebuffer id to scene renderer --- ui/gameMainWindow.cpp | 2 +- ui/sceneRenderer.cpp | 6 +++--- ui/sceneRenderer.h | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index b6e0075..dfb51e9 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -30,7 +30,7 @@ public: }; GameMainWindow::GameMainWindow(size_t w, size_t h) : - Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {size}, camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, rdiv(w, h), + Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {size, 0}, camera {{-1250.0F, -1250.0F, 35.0F}, quarter_pi, rdiv(w, h), 0.1F, 10000.0F} { uiComponents.create(glm::vec2 {-1150, -1150}); diff --git a/ui/sceneRenderer.cpp b/ui/sceneRenderer.cpp index 5ef0379..9432710 100644 --- a/ui/sceneRenderer.cpp +++ b/ui/sceneRenderer.cpp @@ -10,7 +10,7 @@ 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) : lighting {lightingShader_vs, lightingShader_fs} +SceneRenderer::SceneRenderer(glm::ivec2 size, GLuint o) : output {o}, lighting {lightingShader_vs, lightingShader_fs} { glBindVertexArray(displayVAO); glBindBuffer(GL_ARRAY_BUFFER, displayVBO); @@ -43,7 +43,7 @@ SceneRenderer::SceneRenderer(glm::ivec2 size) : lighting {lightingShader_vs, lig if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { throw std::runtime_error("Framebuffer not complete!"); } - glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, output); } void @@ -58,7 +58,7 @@ SceneRenderer::render(std::function content) const glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); content(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, output); // Lighting pass glDisable(GL_BLEND); diff --git a/ui/sceneRenderer.h b/ui/sceneRenderer.h index 6c96418..9352fc9 100644 --- a/ui/sceneRenderer.h +++ b/ui/sceneRenderer.h @@ -7,11 +7,12 @@ class SceneRenderer { public: - explicit SceneRenderer(glm::ivec2 size); + explicit SceneRenderer(glm::ivec2 size, GLuint output); void render(std::function content) const; private: + GLuint output; glFrameBuffer gBuffer; glTexture gPosition, gNormal, gAlbedoSpec; glRenderBuffer depth; -- cgit v1.2.3