summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-11-18 21:41:15 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-11-18 21:41:15 +0000
commit0cea9c894eb514c70ff7c8edd0ccfa59c1f07a1a (patch)
tree57f1f7b55b76402196e46638d8a223397170c713 /ui
parentRename rdiv to ratio and add a vec2 override (diff)
downloadilt-0cea9c894eb514c70ff7c8edd0ccfa59c1f07a1a.tar.bz2
ilt-0cea9c894eb514c70ff7c8edd0ccfa59c1f07a1a.tar.xz
ilt-0cea9c894eb514c70ff7c8edd0ccfa59c1f07a1a.zip
Save size of output in SceneRender and set viewport accordingly
Diffstat (limited to 'ui')
-rw-r--r--ui/gameMainWindow.cpp2
-rw-r--r--ui/sceneRenderer.cpp10
-rw-r--r--ui/sceneRenderer.h1
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<ManualCameraController>(glm::vec2 {-1150, -1150});
auto gms = uiComponents.create<GameMainSelector>(&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<glm::vec4, 4> 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<void(const SceneShader &)> 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<void(const SceneShader &)> 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;