diff options
| author | Vaino Kauppila <vaino@vke.fi> | 2026-07-02 22:58:25 +0300 |
|---|---|---|
| committer | Vaino Kauppila <vaino@vke.fi> | 2026-07-02 23:47:07 +0300 |
| commit | cd0c08dc7ce754473178ad3f32f7740a1dddc1eb (patch) | |
| tree | 589c676b41d6f3d322ea5ce339ddb0811f29ec31 /src/engine/renderer.hpp | |
| download | forts_clone-cd0c08dc7ce754473178ad3f32f7740a1dddc1eb.tar.gz forts_clone-cd0c08dc7ce754473178ad3f32f7740a1dddc1eb.zip | |
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.
Diffstat (limited to 'src/engine/renderer.hpp')
| -rw-r--r-- | src/engine/renderer.hpp | 60 |
1 files changed, 60 insertions, 0 deletions
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 <SDL3/SDL.h> +#include <vector> +#include <string> +#include <unordered_map> + +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<SDL_Vertex> fan_scratch_; // reused by draw_radial_timer + std::unordered_map<std::string, SDL_Texture*> tex_cache_; +}; |
