From cd0c08dc7ce754473178ad3f32f7740a1dddc1eb Mon Sep 17 00:00:00 2001 From: Vaino Kauppila Date: Thu, 2 Jul 2026 22:58:25 +0300 Subject: Initial import: LibreForts (M0-M5 in progress) Open-source Forts clone: custom C++20 engine + data-driven (Lua) 2D physics artillery RTS. - Building: node/strut graph on a stiff mass-spring solver (canon Forts model), triangulation rigidity, axial + 30-degree angle-stress breaking, cascading collapse, fire (DoT + spread), ground destroys debris. - Weapons (M4): cannon (ballistic) + laser (beam/ignite) with select-and-aim-in- arc UX; splash / beam damage; bg-brace passthrough. - Devices + economy (M5): reactors + win/loss + restart, mines/turbines/battery, metal deposits, storage caps, per-shot energy cost. - Data-driven via Lua/sol2 with a layered mod loader; enemy-fort scenario mod. - Renderer: SDL3 + textures + ImGui dev UI. stb_image + ImGui vendored. - Assets: CC0 placeholders only; real game art loaded at runtime from the user's own install via forts: paths (bring-your-own; nothing copyrighted committed). See README.md / CLAUDE.md and research/ + requirements/ for detail. --- src/engine/renderer.hpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/engine/renderer.hpp (limited to 'src/engine/renderer.hpp') diff --git a/src/engine/renderer.hpp b/src/engine/renderer.hpp new file mode 100644 index 0000000..ddc8055 --- /dev/null +++ b/src/engine/renderer.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include +#include +#include +#include + +class Camera; + +class Renderer { +public: + Renderer() = default; + + bool init(SDL_Window* window, int width, int height); + void shutdown(); + + void begin_frame(Camera& camera); + void end_frame(); + void resize(int width, int height); + + // Draw a filled axis-aligned box in world coordinates. + void draw_box(float cx, float cy, float half_w, float half_h, + float angle, float r, float g, float b, float a); + + // Load a texture (cached by path). Returns nullptr on failure. + SDL_Texture* load_texture(const std::string& path); + + // Draw a textured quad in world coordinates, colour-modulated by (r,g,b,a). + void draw_sprite(float cx, float cy, float half_w, float half_h, + float angle, SDL_Texture* tex, + float r = 1.0f, float g = 1.0f, float b = 1.0f, float a = 1.0f); + + // Draw a simple HUD bar in screen pixels (top-left origin). + void draw_hud_bar(float x, float y, float fill, + float r, float g, float b); + + // Draw a radial (pie) countdown at a world position. `frac` in [0,1] is the + // remaining portion drawn as a filled wedge over a dim background ring. + void draw_radial_timer(float cx, float cy, float radius_world, float frac, + float r, float g, float b, float a); + + // Draw a filled wedge (world space) between world angles a0..a1 — used for + // a weapon's firing arc. + void draw_arc(float cx, float cy, float radius_world, float a0, float a1, + float r, float g, float b, float a); + + int width() const { return width_; } + int height() const { return height_; } + + SDL_Renderer* sdl_renderer() const { return sdl_renderer_; } + +private: + SDL_Renderer* sdl_renderer_ = nullptr; + Camera* current_cam_ = nullptr; + int width_ = 1280; + int height_ = 720; + bool imgui_ready_ = false; + std::vector fan_scratch_; // reused by draw_radial_timer + std::unordered_map tex_cache_; +}; -- cgit v1.3