summaryrefslogtreecommitdiff
path: root/ui/gameMainWindow.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-12-13 23:47:30 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-12-13 23:47:30 +0000
commit1686a01b6ae7467e71eac247078248de4a3b3423 (patch)
tree53716ce767b1b775dc06f658a41a647bddbbeac1 /ui/gameMainWindow.cpp
parentMove TickDuration to its own files (diff)
downloadilt-1686a01b6ae7467e71eac247078248de4a3b3423.tar.bz2
ilt-1686a01b6ae7467e71eac247078248de4a3b3423.tar.xz
ilt-1686a01b6ae7467e71eac247078248de4a3b3423.zip
Refactor to start splitting out UI components
Diffstat (limited to 'ui/gameMainWindow.cpp')
-rw-r--r--ui/gameMainWindow.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp
new file mode 100644
index 0000000..4421098
--- /dev/null
+++ b/ui/gameMainWindow.cpp
@@ -0,0 +1,43 @@
+#include "gameMainWindow.h"
+#include "collection.hpp"
+#include "gfx/camera_controller.h"
+#include "manualCameraController.h"
+#include "ui/window.h"
+#include <GL/glew.h>
+#include <SDL2/SDL.h>
+#include <game/gamestate.h>
+#include <game/worldobject.h> // IWYU pragma: keep
+#include <gfx/renderable.h>
+#include <glm/glm.hpp>
+#include <maths.h>
+#include <memory>
+
+GameMainWindow::GameMainWindow(size_t w, size_t h) :
+ Window {static_cast<int>(w), static_cast<int>(h), "I Like Trains"}, uiShader {w, h}, camera {{-1250.0F, -1250.0F,
+ 35.0F},
+ 70.0F, rdiv(w, h),
+ 0.1F, 10000.0F}
+{
+ inputStack.create<ManualCameraController>(glm::vec2 {-1150, -1150});
+
+ shader.setUniform("lightDirection", glm::normalize(glm::vec3 {1, 0, -1}));
+ shader.setUniform("lightColor", {.6, .6, .6});
+ shader.setUniform("ambientColor", {0.5, 0.5, 0.5});
+}
+
+void
+GameMainWindow::tick(TickDuration)
+{
+ inputStack.apply<CameraController>(&CameraController::updateCamera, &camera);
+ shader.setView(camera.GetViewProjection());
+}
+
+void
+GameMainWindow::Refresh(const GameState * gameState) const
+{
+ SDL_GL_MakeCurrent(m_window, m_glContext);
+ glEnable(GL_DEPTH_TEST);
+ gameState->world.apply<Renderable>(&Renderable::render, shader);
+ glDisable(GL_DEPTH_TEST);
+ // do ui bits
+}