From bcdc5c98b356d926939b226a3962d97763295d3b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 18 Dec 2021 19:28:54 +0000 Subject: Window handles UIComponent rendering --- ui/gameMainWindow.cpp | 3 +-- ui/gameMainWindow.h | 1 - ui/uiComponent.h | 12 ++++++++++++ ui/window.cpp | 11 ++++++++++- ui/window.h | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 ui/uiComponent.h (limited to 'ui') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index b41fc56..cd9d3e4 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -34,6 +34,5 @@ GameMainWindow::render(const GameState * gameState) const { glEnable(GL_DEPTH_TEST); gameState->world.apply(&Renderable::render, shader); - glDisable(GL_DEPTH_TEST); - // do ui bits + Window::render(gameState); } diff --git a/ui/gameMainWindow.h b/ui/gameMainWindow.h index 36f8e80..8b88f11 100644 --- a/ui/gameMainWindow.h +++ b/ui/gameMainWindow.h @@ -4,7 +4,6 @@ #include "chronology.hpp" #include "gfx/gl/camera.h" #include "gfx/gl/shader.h" -#include "gfx/gl/uiShader.h" #include "window.h" #include diff --git a/ui/uiComponent.h b/ui/uiComponent.h new file mode 100644 index 0000000..cd21de3 --- /dev/null +++ b/ui/uiComponent.h @@ -0,0 +1,12 @@ +#ifndef UICOMPONENT_H +#define UICOMPONENT_H + +class UIShader; + +class UIComponent { +public: + virtual ~UIComponent() = default; + virtual void render(const UIShader &) const = 0; +}; + +#endif diff --git a/ui/window.cpp b/ui/window.cpp index d9e0467..cd4a202 100644 --- a/ui/window.cpp +++ b/ui/window.cpp @@ -1,5 +1,6 @@ #include "window.h" -#include "ui/inputHandler.h" +#include "inputHandler.h" +#include "uiComponent.h" #include #include #include @@ -73,3 +74,11 @@ Window::refresh(const GameState * gameState) const swapBuffers(); } + +void +Window::render(const GameState *) const +{ + uiShader.use(); + glDisable(GL_DEPTH_TEST); + inputStack.apply(&UIComponent::render, uiShader); +} diff --git a/ui/window.h b/ui/window.h index 97a0253..9c6d023 100644 --- a/ui/window.h +++ b/ui/window.h @@ -30,7 +30,7 @@ public: protected: SDL_GLContext glContext() const; - virtual void render(const GameState *) const = 0; + virtual void render(const GameState *) const; using SDL_WindowPtr = wrapped_ptrt; SDL_WindowPtr m_window; -- cgit v1.2.3