From 3eed7751c9f2a7ae5cdba1d233751f82dd8d9b10 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 3 Nov 2023 21:31:35 +0000 Subject: Don't request a specific OpenGL version, just check we get something sufficient from gladLoadGL --- ui/applicationBase.cpp | 3 --- ui/window.cpp | 8 +++----- 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/applicationBase.cpp b/ui/applicationBase.cpp index 32af3af..2be1f6c 100644 --- a/ui/applicationBase.cpp +++ b/ui/applicationBase.cpp @@ -21,9 +21,6 @@ ApplicationBase::ApplicationBase() setGlAttribute(SDL_GL_DEPTH_SIZE, 16); setGlAttribute(SDL_GL_DOUBLEBUFFER, 1); - setGlAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - setGlAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); - setGlAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); setGlAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); } diff --git a/ui/window.cpp b/ui/window.cpp index 93e85bd..6855aa0 100644 --- a/ui/window.cpp +++ b/ui/window.cpp @@ -1,17 +1,15 @@ #include "window.h" #include "uiComponent.h" -#include "worldOverlay.h" #include #include #include -#include -#include Window::GLInitHelper::GLInitHelper() { [[maybe_unused]] static auto init = []() { - if (const auto version = gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)); version != 40006) { - throw std::runtime_error {std::to_string(version)}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + if (const auto version = gladLoadGL(reinterpret_cast(SDL_GL_GetProcAddress)); version < 30003) { + throw std::runtime_error {"Insufficient OpenGL version: " + std::to_string(version)}; } else { return version; -- cgit v1.2.3 From 2f8d7643d03f39fa848576692264d0fe3a37ed91 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 6 Nov 2023 20:48:33 +0000 Subject: Reformat with new clang-format --- ui/font.cpp | 1 + ui/font.h | 1 + ui/gameMainSelector.cpp | 1 + ui/gameMainWindow.cpp | 4 ++++ ui/iconButton.h | 1 + ui/modeHelper.h | 1 + ui/text.cpp | 1 + ui/text.h | 1 + ui/uiComponent.cpp | 1 + ui/uiComponent.h | 1 + ui/uiComponentPlacer.cpp | 1 + ui/window.h | 1 + 12 files changed, 15 insertions(+) (limited to 'ui') diff --git a/ui/font.cpp b/ui/font.cpp index 108f905..ebd856d 100644 --- a/ui/font.cpp +++ b/ui/font.cpp @@ -14,6 +14,7 @@ #include #include #include + // IWYU pragma: no_forward_declare FT_LibraryRec_ std::string diff --git a/ui/font.h b/ui/font.h index 6c86e18..2f3337f 100644 --- a/ui/font.h +++ b/ui/font.h @@ -31,6 +31,7 @@ public: glm::ivec2 bearing; long advance; }; + struct FontTexture { glTexture texture; unsigned int used; diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index 081718d..6c6935c 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -15,6 +15,7 @@ #include GameMainSelector::GameMainSelector(const Camera * c, glm::vec2 size) : UIComponent {{{}, size}}, camera {c} { } + constexpr glm::vec2 TargetPos {5, 45}; void diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index c35c9c6..b94accd 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -48,6 +48,7 @@ GameMainWindow::render() const SceneRenderer::render(*this); Window::render(); } + void GameMainWindow::content(const SceneShader & shader) const { @@ -59,17 +60,20 @@ GameMainWindow::content(const SceneShader & shader) const gameState->world.apply(&Renderable::render, shader); uiComponents.apply(&WorldOverlay::render, shader); } + void GameMainWindow::environment(const SceneShader & s, const SceneRenderer & r) const { // default for now SceneProvider::environment(s, r); } + void GameMainWindow::lights(const SceneShader & shader) const { gameState->world.apply(&Renderable::lights, shader); } + void GameMainWindow::shadows(const ShadowMapper & shadowMapper) const { diff --git a/ui/iconButton.h b/ui/iconButton.h index 6ac9317..0afe92d 100644 --- a/ui/iconButton.h +++ b/ui/iconButton.h @@ -10,6 +10,7 @@ class UIShader; union SDL_Event; static const constexpr glm::vec2 ICON_SIZE {32.F, 32.F}; + class IconButton : public UIComponent { public: IconButton(const std::string & icon, glm::vec2 position, UIEvent click); diff --git a/ui/modeHelper.h b/ui/modeHelper.h index 77707f2..d20f2db 100644 --- a/ui/modeHelper.h +++ b/ui/modeHelper.h @@ -4,6 +4,7 @@ union SDL_Event; enum ModeSecondClick { Unset, Reset, NoAction }; + template class Mode { public: explicit Mode(Target & t) : target {t} { } diff --git a/ui/text.cpp b/ui/text.cpp index d24c268..b776b90 100644 --- a/ui/text.cpp +++ b/ui/text.cpp @@ -12,6 +12,7 @@ #include const std::filesystem::path font {"/usr/share/fonts/hack/Hack-Regular.ttf"}; + Text::Text(std::string_view s, Position pos, glm::vec3 c) : UIComponent {pos}, colour {c} { for (const auto & textureQuads : diff --git a/ui/text.h b/ui/text.h index 9fe87d1..de2fe2e 100644 --- a/ui/text.h +++ b/ui/text.h @@ -25,6 +25,7 @@ private: glVertexArray vao; glBuffer vbo; }; + std::vector models; glm::vec3 colour; }; diff --git a/ui/uiComponent.cpp b/ui/uiComponent.cpp index e480fbc..aa4838d 100644 --- a/ui/uiComponent.cpp +++ b/ui/uiComponent.cpp @@ -20,6 +20,7 @@ UIComponent::Position::operator&(const glm::vec2 & pos) const { return (pos.x >= origin.x && pos.y >= origin.y && pos.x < origin.x + size.x && pos.y < origin.y + size.y); } + bool UIComponent::Position::operator&(const SDL_MouseButtonEvent & pos) const { diff --git a/ui/uiComponent.h b/ui/uiComponent.h index 75c2284..71d2659 100644 --- a/ui/uiComponent.h +++ b/ui/uiComponent.h @@ -18,6 +18,7 @@ public: bool operator&(const SDL_MouseButtonEvent &) const; bool operator&(const glm::vec2 &) const; }; + explicit UIComponent(Position); virtual ~UIComponent() = default; diff --git a/ui/uiComponentPlacer.cpp b/ui/uiComponentPlacer.cpp index 368e772..5e645d8 100644 --- a/ui/uiComponentPlacer.cpp +++ b/ui/uiComponentPlacer.cpp @@ -16,6 +16,7 @@ UIComponentPlacer::next(glm::vec2 size) max = std::max(max, size[1 - axis]); return n; } + glm::vec2 UIComponentPlacer::getLimit() const { diff --git a/ui/window.h b/ui/window.h index 369228a..183a65a 100644 --- a/ui/window.h +++ b/ui/window.h @@ -31,6 +31,7 @@ public: protected: virtual void render() const; + struct GLInitHelper { GLInitHelper(); }; -- cgit v1.2.3 From d6e99a696aa582b81018078b68f6600c8030d643 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 7 Nov 2023 02:51:42 +0000 Subject: WIP typedefing all the things - headers --- ui/builders/freeExtend.h | 2 +- ui/builders/straight.h | 4 ++-- ui/gameMainSelector.cpp | 2 +- ui/gameMainSelector.h | 3 ++- ui/manualCameraController.h | 4 ++-- ui/window.h | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/builders/freeExtend.h b/ui/builders/freeExtend.h index 55fe7ff..b276426 100644 --- a/ui/builders/freeExtend.h +++ b/ui/builders/freeExtend.h @@ -9,5 +9,5 @@ class BuilderFreeExtend : public EditNetwork::Builder { void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override; - std::optional p1; + std::optional p1; }; diff --git a/ui/builders/straight.h b/ui/builders/straight.h index 1cde2b0..cf99a1d 100644 --- a/ui/builders/straight.h +++ b/ui/builders/straight.h @@ -9,7 +9,7 @@ class BuilderStraight : public EditNetwork::Builder { void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override; - void create(Network * network, glm::vec3 p1, glm::vec3 p2) const; + void create(Network * network, Position3D p1, Position3D p2) const; - std::optional p1; + std::optional p1; }; diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index 6c6935c..808e0e4 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -14,7 +14,7 @@ #include #include -GameMainSelector::GameMainSelector(const Camera * c, glm::vec2 size) : UIComponent {{{}, size}}, camera {c} { } +GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { } constexpr glm::vec2 TargetPos {5, 45}; diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h index 98cdf53..88db34b 100644 --- a/ui/gameMainSelector.h +++ b/ui/gameMainSelector.h @@ -1,6 +1,7 @@ #pragma once #include "SDL_events.h" +#include "config/types.h" #include "special_members.h" #include "uiComponent.h" #include "worldOverlay.h" @@ -26,7 +27,7 @@ public: virtual void render(const SceneShader &) const; }; - GameMainSelector(const Camera * c, glm::vec2 size); + GameMainSelector(const Camera * c, ScreenAbsCoord size); void render(const UIShader & shader, const Position & pos) const override; void render(const SceneShader & shader) const override; diff --git a/ui/manualCameraController.h b/ui/manualCameraController.h index d15fa76..46655bc 100644 --- a/ui/manualCameraController.h +++ b/ui/manualCameraController.h @@ -11,7 +11,7 @@ class Camera; class ManualCameraController : public CameraController, public UIComponent { public: - explicit ManualCameraController(glm::vec2 f) : UIComponent {{}}, focus {f} { } + explicit ManualCameraController(Position2D f) : UIComponent {{}}, focus {f} { } bool handleInput(const SDL_Event & e, const Position &) override; void render(const UIShader &, const Position & parentPos) const override; @@ -20,7 +20,7 @@ public: private: bool ctrl {false}, mrb {false}; - glm::vec2 focus; + Position2D focus; float direction {quarter_pi}; float dist {40}, pitch {quarter_pi}; }; diff --git a/ui/window.h b/ui/window.h index 183a65a..8f2b70b 100644 --- a/ui/window.h +++ b/ui/window.h @@ -36,7 +36,7 @@ protected: GLInitHelper(); }; - const glm::ivec2 size; + const ScreenAbsCoord size; SDL_WindowPtr m_window; SDL_GLContextPtr glContext; GLInitHelper glInithelper; -- cgit v1.2.3 From 9c2c3f71065c94a18c02440111b6ff8ca977b90e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 00:40:40 +0000 Subject: WIP typedefing all the things - sources --- ui/builders/straight.cpp | 2 +- ui/gameMainSelector.cpp | 9 +++++---- ui/gameMainWindow.cpp | 4 ++-- ui/manualCameraController.cpp | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp index 4fa9585..9b262bb 100644 --- a/ui/builders/straight.cpp +++ b/ui/builders/straight.cpp @@ -47,7 +47,7 @@ BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_Mou } void -BuilderStraight::create(Network * network, glm::vec3 p1, glm::vec3 p2) const +BuilderStraight::create(Network * network, Position3D p1, Position3D p2) const { network->addStraight(p1, p2); } diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index 808e0e4..a451ee1 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -8,6 +8,7 @@ #include #include // IWYU pragma: keep #include +#include #include #include #include @@ -16,7 +17,7 @@ GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { } -constexpr glm::vec2 TargetPos {5, 45}; +constexpr ScreenAbsCoord TargetPos {5, 45}; void GameMainSelector::render(const UIShader & shader, const Position & parentPos) const @@ -41,7 +42,7 @@ bool GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos) { const auto getRay = [this](const auto & e) { - const auto mouse = glm::vec2 {e.x, e.y} / position.size; + const auto mouse = ScreenRelCoord {e.x, e.y} / position.size; return camera->unProject(mouse); }; if (target) { @@ -72,8 +73,8 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos) void GameMainSelector::defaultClick(const Ray & ray) { - glm::vec2 baryPos {}; - float distance; + Position2D baryPos {}; + float distance {}; if (const auto selected = gameState->world.applyOne(&Selectable::intersectRay, ray, &baryPos, &distance); diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index b94accd..15f1e07 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -31,8 +31,8 @@ public: GameMainWindow::GameMainWindow(size_t w, size_t h) : Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0} { - uiComponents.create(glm::vec2 {-1150, -1150}); - auto gms = uiComponents.create(&camera, glm::vec2 {w, h}); + uiComponents.create(Position2D {-1150, -1150}); + auto gms = uiComponents.create(&camera, ScreenAbsCoord {w, h}); uiComponents.create(gms.get()); } diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp index 8e52b0e..05c1fc5 100644 --- a/ui/manualCameraController.cpp +++ b/ui/manualCameraController.cpp @@ -59,7 +59,7 @@ ManualCameraController::handleInput(const SDL_Event & e, const Position &) pitch = std::clamp(pitch - 0.01F * static_cast(e.motion.yrel), 0.1F, half_pi); } else { - focus += rotate_flat(-direction) * glm::vec2 {-e.motion.xrel, e.motion.yrel}; + focus += rotate_flat(-direction) * Position2D {-e.motion.xrel, e.motion.yrel}; } } return true; -- cgit v1.2.3 From d771fbda2c171cfbc36cc0eb3122c1a02ffbb081 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 9 Nov 2023 01:57:27 +0000 Subject: WIP typedefing just about everything else --- ui/editNetwork.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/editNetwork.h b/ui/editNetwork.h index eb1677e..e1aaa61 100644 --- a/ui/editNetwork.h +++ b/ui/editNetwork.h @@ -21,7 +21,7 @@ public: void render(const SceneShader &) const override; void render(const UIShader & shader, const UIComponent::Position & pos) const override; - using NetworkClickPos = std::variant; + using NetworkClickPos = std::variant; class Builder { public: -- cgit v1.2.3 From 685b33980cc7a346574b24732464f0cbe3115a1f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Nov 2023 01:29:24 +0000 Subject: Switch to millimeters for spatial units Mostly a case of changing far too many magic numbers, something else to fix I guess. I probably missed something. Also there's some hackery when loading 3D models, which are still assumed to be in metres. --- ui/gameMainWindow.cpp | 2 +- ui/manualCameraController.cpp | 4 ++-- ui/manualCameraController.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ui') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 15f1e07..7cf143a 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -31,7 +31,7 @@ public: GameMainWindow::GameMainWindow(size_t w, size_t h) : Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0} { - uiComponents.create(Position2D {-1150, -1150}); + uiComponents.create(Position2D {-1150000, -1150000}); auto gms = uiComponents.create(&camera, ScreenAbsCoord {w, h}); uiComponents.create(gms.get()); } diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp index 05c1fc5..f6993a8 100644 --- a/ui/manualCameraController.cpp +++ b/ui/manualCameraController.cpp @@ -59,12 +59,12 @@ ManualCameraController::handleInput(const SDL_Event & e, const Position &) pitch = std::clamp(pitch - 0.01F * static_cast(e.motion.yrel), 0.1F, half_pi); } else { - focus += rotate_flat(-direction) * Position2D {-e.motion.xrel, e.motion.yrel}; + focus += rotate_flat(-direction) * (Position2D {-e.motion.xrel, e.motion.yrel} * dist / 2.0F); } } return true; case SDL_MOUSEWHEEL: - dist = std::clamp(dist - static_cast(e.wheel.y) * 4.F, 5.F, 200.F); + dist = std::clamp(dist - static_cast(e.wheel.y) * 400.F, 5.F, 200000.F); break; } return false; diff --git a/ui/manualCameraController.h b/ui/manualCameraController.h index 46655bc..1efaee1 100644 --- a/ui/manualCameraController.h +++ b/ui/manualCameraController.h @@ -22,5 +22,5 @@ private: bool ctrl {false}, mrb {false}; Position2D focus; float direction {quarter_pi}; - float dist {40}, pitch {quarter_pi}; + float dist {4000}, pitch {quarter_pi}; }; -- cgit v1.2.3