From de61720146a1ce0640322dff992462bfbecafdc3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 18 Dec 2021 15:08:45 +0000 Subject: Push uiShader into the window class --- ui/gameMainWindow.cpp | 5 +---- ui/gameMainWindow.h | 1 - ui/window.cpp | 13 +++++++++---- ui/window.h | 4 +++- 4 files changed, 13 insertions(+), 10 deletions(-) (limited to 'ui') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 7d5e19b..b41fc56 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -13,10 +13,7 @@ #include GameMainWindow::GameMainWindow(size_t w, size_t h) : - Window {static_cast(w), static_cast(h), "I Like Trains"}, uiShader {w, h}, camera {{-1250.0F, -1250.0F, - 35.0F}, - 70.0F, rdiv(w, h), - 0.1F, 10000.0F} + Window {w, h, "I Like Trains"}, camera {{-1250.0F, -1250.0F, 35.0F}, 70.0F, rdiv(w, h), 0.1F, 10000.0F} { inputStack.create(glm::vec2 {-1150, -1150}); diff --git a/ui/gameMainWindow.h b/ui/gameMainWindow.h index 124d776..36f8e80 100644 --- a/ui/gameMainWindow.h +++ b/ui/gameMainWindow.h @@ -19,7 +19,6 @@ public: void render(const GameState * gameState) const override; private: - UIShader uiShader; Shader shader; Camera camera; }; diff --git a/ui/window.cpp b/ui/window.cpp index 2dc0c2a..d9e0467 100644 --- a/ui/window.cpp +++ b/ui/window.cpp @@ -21,11 +21,16 @@ SDL_GL_CreateContextAndGlewInit(SDL_Window * w) using GL_Context = std::remove_pointer_t; using SDL_GLContextPtr = wrapped_ptrt; -Window::Window(int width, int height, const std::string & title) : - m_window {title.c_str(), static_cast(SDL_WINDOWPOS_CENTERED), static_cast(SDL_WINDOWPOS_CENTERED), width, - height, static_cast(SDL_WINDOW_OPENGL)} +Window::Window(size_t width, size_t height, const std::string & title) : + m_window {title.c_str(), static_cast(SDL_WINDOWPOS_CENTERED), static_cast(SDL_WINDOWPOS_CENTERED), + static_cast(width), static_cast(height), static_cast(SDL_WINDOW_OPENGL)}, + uiShader {[this](auto w) { + // must call glContent before creating the shader + glContext(); + return w; + }(width), + height} { - glContext(); } void diff --git a/ui/window.h b/ui/window.h index 8bfc9c3..97a0253 100644 --- a/ui/window.h +++ b/ui/window.h @@ -3,6 +3,7 @@ #include "chronology.hpp" #include "collection.hpp" +#include "gfx/gl/uiShader.h" #include "inputHandler.h" // IWYU pragma: keep #include "ptr.hpp" #include @@ -14,7 +15,7 @@ class GameState; class Window { public: - Window(int width, int height, const std::string & title); + Window(size_t width, size_t height, const std::string & title); virtual ~Window() = default; NO_COPY(Window); @@ -34,6 +35,7 @@ protected: using SDL_WindowPtr = wrapped_ptrt; SDL_WindowPtr m_window; Collection inputStack; + UIShader uiShader; }; #endif -- cgit v1.2.3