Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
SpriteRenderer.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <memory>
5#include <string>
6#include <vector>
7
8#include "Types.h"
10
11namespace mnd
12{
13
14class Texture;
15
17{
18public:
19 bool Init();
20 void Shutdown();
21
22 void DrawSprite(Texture *texture, const vec2 &position, const vec2 &size, const vec4 &color = vec4(1.0F));
23 void DrawSprite(const std::string &assetPath, const vec2 &position, const vec2 &size, const vec4 &color = vec4(1.0F));
24 void DrawRect(const vec2 &position, const vec2 &size, const vec4 &color);
25 void DrawText(const std::string &text, const vec2 &position, f32 pixelHeight, const vec4 &color = vec4(1.0F));
26
27 void Flush(int viewportWidth, int viewportHeight);
28
29private:
30 struct Vertex
31 {
32 vec2 position;
33 vec2 uv;
34 vec4 color;
35 };
36
37 struct DrawCommand
38 {
39 GLuint texture = 0;
40 bool redOnly = false;
41 std::array<Vertex, 6> vertices {};
42 };
43
44 struct Glyph
45 {
46 f32 x0 = 0.0F;
47 f32 y0 = 0.0F;
48 f32 x1 = 0.0F;
49 f32 y1 = 0.0F;
50 f32 xoff = 0.0F;
51 f32 yoff = 0.0F;
52 f32 xadvance = 0.0F;
53 };
54
55 bool LoadDefaultFont();
56 void QueueQuad(GLuint texture,
57 bool redOnly,
58 const vec2 &position,
59 const vec2 &size,
60 const vec2 &uvMin,
61 const vec2 &uvMax,
62 const vec4 &color);
63
64 GLuint m_shader = 0;
65 GLuint m_vao = 0;
66 GLuint m_vbo = 0;
67 GLuint m_fontTexture = 0;
68 GLuint m_whiteTexture = 0;
69
70 std::array<unsigned char, 512 * 512> m_fontBitmap {};
71 std::array<Glyph, 96> m_glyphs {};
72 f32 m_fontBakeHeight = 32.0F;
73 bool m_fontReady = false;
74 std::vector<DrawCommand> m_commands;
75};
76
77} // namespace mnd
unsigned int GLuint
Definition GLForward.h:11
Engine-wide primitive type aliases and GLM math imports.
void DrawSprite(Texture *texture, const vec2 &position, const vec2 &size, const vec4 &color=vec4(1.0F))
void DrawText(const std::string &text, const vec2 &position, f32 pixelHeight, const vec4 &color=vec4(1.0F))
void DrawRect(const vec2 &position, const vec2 &size, const vec4 &color)
void Flush(int viewportWidth, int viewportHeight)
2D OpenGL texture object wrapping a GL_TEXTURE_2D handle.
Definition Texture.h:41
glm::vec2 vec2
2-component float vector (e.g. UV coordinates, mouse position).
Definition Types.h:50
glm::vec4 vec4
4-component float vector (e.g. RGBA colour, homogeneous coords).
Definition Types.h:52
float f32
32-bit IEEE float — the standard GL scalar type.
Definition Types.h:40