Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
engine_structs.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "imports.h"
4 
5 
6 
7 // Core struct (engine stuff) - 0.0.1
8 
14 struct Texture {
15  Uint32 id = 0;
16  int width = 0;
17  int height = 0;
18  std::string path;
19 
20  Texture() = default;
21 
23 
24  void* mtlTexture = nullptr; // id<MTLTexture>
25 
26 };
27 
33 struct Rect2 {
34  float x, y, width, height;
35 
36  Rect2() : x(0), y(0), width(0), height(0) {}
37 
38  Rect2(float x, float y, float width, float height) : x(x), y(y), width(width), height(height) {}
39 
40  [[nodiscard]] bool is_zero() const;
41 
42  [[nodiscard]] glm::vec2 top_left() const;
43 
44  [[nodiscard]] glm::vec2 bottom_right() const ;
45 
46 };
47 
53 struct Recti {
54  int x, y, width, height;
55 
56  Recti() : x(0), y(0), width(0), height(0) {}
57 
58  Recti(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) {}
59 
60  [[nodiscard]] bool is_zero() const;
61 
62  [[nodiscard]] glm::ivec2 top_left() const;
63 
64  [[nodiscard]] glm::ivec2 bottom_right() const ;
65 };
66 
72 struct Sizei {
73  int width;
74  int height;
75 };
76 
77 
85 struct Color {
86  unsigned char r;
87  unsigned char g;
88  unsigned char b;
89  unsigned char a;
90 
91  [[nodiscard]] glm::vec4 normalize_color() const;
92 
93  [[nodiscard]] Color to_rgba(float r, float g, float b, float a) const;
94 
95  bool operator==(const Color& other) const;
96 
97  static const Color RED;
98  static const Color GREEN;
99  static const Color BLUE;
100  static const Color WHITE;
101  static const Color BLACK;
102  static const Color YELLOW;
103  static const Color CYAN;
104  static const Color MAGENTA;
105  // static const Color TRANSPARENT;
106 };
107 
113 struct Character {
114  GLuint texture_id;
115  glm::ivec2 size;
116  glm::ivec2 bearing;
117  GLuint advance;
118 };
119 
125 struct Glyph {
126  float x0, y0, w, h;
127  const Character* ch;
128  const glm::vec4 token_color = glm::vec4(1.f);
129 };
137 struct Font {
139  std::string font_path;
140  int font_size = 48;
141  float kerning = 0.0f;
142  int ascent = 0, descent = 0, line_gap = 0;
143  float scale = 1.0f;
144 
145  [[nodiscard]] bool is_valid() const;
146 
147  Font() = default;
148  ~Font();
149 };
150 
151 
152 Sizei calc_text_size(const std::string& text, const Font& font, float font_size = 0.0f);
Sizei calc_text_size(const std::string &text, const Font &font, float font_size=0.0f)
std::unordered_map< K, V > HashMap
Definition: imports.h:12
Font Character struct.
Definition: engine_structs.h:113
glm::ivec2 size
Definition: engine_structs.h:115
GLuint advance
Definition: engine_structs.h:117
glm::ivec2 bearing
Definition: engine_structs.h:116
GLuint texture_id
Definition: engine_structs.h:114
Color struct.
Definition: engine_structs.h:85
static const Color GREEN
Definition: engine_structs.h:98
static const Color WHITE
Definition: engine_structs.h:100
unsigned char a
Definition: engine_structs.h:89
static const Color BLACK
Definition: engine_structs.h:101
static const Color BLUE
Definition: engine_structs.h:99
static const Color YELLOW
Definition: engine_structs.h:102
unsigned char b
Definition: engine_structs.h:88
static const Color RED
Definition: engine_structs.h:97
unsigned char r
Definition: engine_structs.h:86
static const Color MAGENTA
Definition: engine_structs.h:104
unsigned char g
Definition: engine_structs.h:87
static const Color CYAN
Definition: engine_structs.h:103
glm::vec4 normalize_color() const
Definition: engine_structs.cpp:47
bool operator==(const Color &other) const
Definition: engine_structs.cpp:68
Color to_rgba(float r, float g, float b, float a) const
Definition: engine_structs.cpp:58
Font struct.
Definition: engine_structs.h:137
int descent
Definition: engine_structs.h:142
float scale
Definition: engine_structs.h:143
std::string font_path
Definition: engine_structs.h:139
float kerning
Definition: engine_structs.h:141
int line_gap
Definition: engine_structs.h:142
bool is_valid() const
Definition: engine_structs.cpp:43
Font()=default
int font_size
Definition: engine_structs.h:140
HashMap< char, Character > characters
Definition: engine_structs.h:138
int ascent
Definition: engine_structs.h:142
Glyph struct.
Definition: engine_structs.h:125
float x0
Definition: engine_structs.h:126
float y0
Definition: engine_structs.h:126
const Character * ch
Definition: engine_structs.h:127
float h
Definition: engine_structs.h:126
float w
Definition: engine_structs.h:126
const glm::vec4 token_color
Definition: engine_structs.h:128
Float rectangle struct.
Definition: engine_structs.h:33
float x
Definition: engine_structs.h:34
glm::vec2 top_left() const
Definition: engine_structs.cpp:24
glm::vec2 bottom_right() const
Definition: engine_structs.cpp:27
bool is_zero() const
Definition: engine_structs.cpp:20
Rect2(float x, float y, float width, float height)
Definition: engine_structs.h:38
float height
Definition: engine_structs.h:34
Rect2()
Definition: engine_structs.h:36
float width
Definition: engine_structs.h:34
float y
Definition: engine_structs.h:34
Integer rectangle struct.
Definition: engine_structs.h:53
int width
Definition: engine_structs.h:54
glm::ivec2 top_left() const
Definition: engine_structs.cpp:35
Recti()
Definition: engine_structs.h:56
int y
Definition: engine_structs.h:54
int x
Definition: engine_structs.h:54
bool is_zero() const
Definition: engine_structs.cpp:31
glm::ivec2 bottom_right() const
Definition: engine_structs.cpp:39
int height
Definition: engine_structs.h:54
Recti(int x, int y, int width, int height)
Definition: engine_structs.h:58
Integer Size struct.
Definition: engine_structs.h:72
int height
Definition: engine_structs.h:74
int width
Definition: engine_structs.h:73
Texture base class.
Definition: engine_structs.h:14
int width
Definition: engine_structs.h:16
Texture()=default
void * mtlTexture
Definition: engine_structs.h:24
std::string path
Definition: engine_structs.h:18
int height
Definition: engine_structs.h:17