group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
HudContext.hpp
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "HudTypes.hpp"
7
8#include <array>
9#include <vector>
10
11class SdfAtlas;
12
18{
19public:
21 void init(const SdfAtlas* atlas);
22
24 void beginFrame();
25
26 // ── Primitives ──────────────────────────────────────────────────────
27
28 void rect(float x, float y, float w, float h, HudColor color);
29 void rectOutline(float x, float y, float w, float h, float thickness, HudColor color);
30 void roundedRect(float x, float y, float w, float h, float radius, HudColor color);
31 void rotatedRect(float cx, float cy, float w, float h, float angleDeg, HudColor color);
32
33 // ── Bars ────────────────────────────────────────────────────────────
34
35 void bar(float x, float y, float w, float h, float fill01, HudColor fg, HudColor bg);
36
37 // ── Text ────────────────────────────────────────────────────────────
38
39 void text(const char* str, float x, float y, float size, HudColor color, HudAlign align = HudAlign::Left);
40 float measureText(const char* str, float size) const;
41
42 // ── Icons ───────────────────────────────────────────────────────────
43
44 void icon(HudIcon id, float x, float y, float size, HudColor tint = HudColor::white());
45
46 // ── Crosshair ───────────────────────────────────────────────────────
47
48 void crosshair(const CrosshairStyle& style, float screenW, float screenH);
49
50 // ── Vignette ────────────────────────────────────────────────────────
51
56 void vignette(float screenW, float screenH, HudColor color);
57
58 // ── Clipping ────────────────────────────────────────────────────────
59
60 void pushClipRect(float x, float y, float w, float h);
61 void popClipRect();
62
65 void endFrame();
66
67 // ── Access for HudRenderer ──────────────────────────────────────────
68
69 [[nodiscard]] const std::vector<HudVertex>& vertices() const { return vertices_; }
70
73 [[nodiscard]] const std::vector<std::array<float, 6>>& clipSpans() const { return clipSpans_; }
74
75private:
76 const SdfAtlas* sdfAtlas_ = nullptr;
77 std::vector<HudVertex> vertices_;
78 std::vector<std::array<float, 6>> clipSpans_;
79
80 // Clip stack: each entry is {x, y, w, h}. Empty = no clip.
81 std::vector<std::array<float, 4>> clipStack_;
82 uint32_t spanStartVertex_ = 0;
83 bool spanDirty_ = false;
84
86 void emitQuad(float x,
87 float y,
88 float w,
89 float h,
90 float u0,
91 float v0,
92 float u1,
93 float v1,
94 HudColor color,
95 float texMode,
96 float sd0 = 0.f,
97 float sd1 = 0.f,
98 float sd2 = 0.f);
99
101 void flushClipSpan();
102};
Shared types for the HUD system.
HudAlign
Definition HudTypes.hpp:46
@ Left
Definition HudTypes.hpp:47
HudIcon
Icon identifiers for the HUD icon atlas.
Definition HudTypes.hpp:54
Accumulates HUD geometry during a frame for batch rendering.
Definition HudContext.hpp:18
void beginFrame()
Clear all geometry for a new frame.
Definition HudContext.cpp:18
void bar(float x, float y, float w, float h, float fill01, HudColor fg, HudColor bg)
Definition HudContext.cpp:167
const SdfAtlas * sdfAtlas_
Definition HudContext.hpp:76
const std::vector< std::array< float, 6 > > & clipSpans() const
Clip rect spans: {startVertex, vertexCount, x, y, w, h}.
Definition HudContext.hpp:73
void flushClipSpan()
Flush the current clip span before changing scissor state.
Definition HudContext.cpp:71
void pushClipRect(float x, float y, float w, float h)
Definition HudContext.cpp:276
void init(const SdfAtlas *atlas)
Bind the SDF atlas for text layout (glyph metrics).
Definition HudContext.cpp:13
void rotatedRect(float cx, float cy, float w, float h, float angleDeg, HudColor color)
Definition HudContext.cpp:106
void vignette(float screenW, float screenH, HudColor color)
Draw a full-screen radial vignette overlay.
Definition HudContext.cpp:268
std::vector< std::array< float, 6 > > clipSpans_
Definition HudContext.hpp:78
uint32_t spanStartVertex_
Vertex index where current clip span started.
Definition HudContext.hpp:82
std::vector< HudVertex > vertices_
Definition HudContext.hpp:77
void text(const char *str, float x, float y, float size, HudColor color, HudAlign align=HudAlign::Left)
Definition HudContext.cpp:177
float measureText(const char *str, float size) const
Definition HudContext.cpp:221
void rectOutline(float x, float y, float w, float h, float thickness, HudColor color)
Definition HudContext.cpp:138
void icon(HudIcon id, float x, float y, float size, HudColor tint=HudColor::white())
Definition HudContext.cpp:238
void emitQuad(float x, float y, float w, float h, float u0, float v0, float u1, float v1, HudColor color, float texMode, float sd0=0.f, float sd1=0.f, float sd2=0.f)
Emit 6 vertices for a textured quad.
Definition HudContext.cpp:36
const std::vector< HudVertex > & vertices() const
Definition HudContext.hpp:69
void crosshair(const CrosshairStyle &style, float screenW, float screenH)
Definition HudContext.cpp:246
bool spanDirty_
Definition HudContext.hpp:83
void endFrame()
Flush any remaining unflushed vertices into a final clip span.
Definition HudContext.cpp:27
void roundedRect(float x, float y, float w, float h, float radius, HudColor color)
Definition HudContext.cpp:146
void rect(float x, float y, float w, float h, HudColor color)
Definition HudContext.cpp:101
std::vector< std::array< float, 4 > > clipStack_
Definition HudContext.hpp:81
void popClipRect()
Definition HudContext.cpp:283
Loads a TTF font, bakes an SDF glyph atlas, and uploads it to the GPU.
Definition SdfAtlas.hpp:18
Crosshair appearance parameters.
Definition HudTypes.hpp:75
RGBA color for HUD elements (linear space, straight alpha).
Definition HudTypes.hpp:15
static constexpr HudColor white()
Definition HudTypes.hpp:21