AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
hud.h
1#pragma once
2
3#include "../rendering/vao.h"
4#include "../rendering/window.h"
5#include "../rendering/texture.h"
6#include "shaderProgram.h"
7#include "window.h"
8#include <vector>
9#include <map>
10#include <glm/glm.hpp>
11
12namespace Aire {
14 class HUD
15 {
16 public:
19 struct HUD_IMAGE {
20 public:
21 std::string name;
22 bool active;
24 glm::vec2 position;
25 glm::vec2 scale;
26 float rotation;
27 };
28
32 public:
33 std::string name;
34 bool active;
37 glm::vec2 position;
38 glm::vec2 scale;
39 float rotation;
40
41 float minValue;
42 float maxValue;
43 float value;
44 };
45
47 struct HUD_TEXT {
48 public:
49 std::string name;
50 bool active;
51 glm::vec2 position;
52 glm::vec2 scale;
53 float rotation;
54 std::string textContent;
55 glm::vec3 colour;
56 };
57
60 HUD(Window* window);
62 ~HUD()=default;
63
64 // Creating the elements
65
73 HUD_IMAGE* NewHUDImage(std::string name, glm::vec2 position, glm::vec2 scale, float rotation, Texture* texture);
74
86 HUD_PROGRESS_BAR* NewHUDProgressBar(std::string name, glm::vec2 position, glm::vec2 scale, float rotation,
87 Texture* underTexture, Texture* progressTexture,
88 float minValue, float maxValue, float value);
89
98 HUD_TEXT* NewHUDText(std::string name, glm::vec2 position, glm::vec2 scale, float rotation, std::string textContent, glm::vec3 colour);
99
100 // Retrieval of the elements
101
105 HUD_IMAGE* GetHUDImageByName(const std::string& name);
106
110 HUD_PROGRESS_BAR* GetHUDProgressBarByName(const std::string& name);
111
115 HUD_TEXT* GetHUDTextByName(const std::string& name);
116
117 // Deletion of elements
118
121 void RemoveHUDImage(HUD_IMAGE* imageToRemove);
122
125 void RemoveHUDProgressBar(HUD_PROGRESS_BAR* progressBarToRemove);
126
129 void RemoveHUDText(HUD_TEXT* textToRemove);
130
132 void Render();
133
137 void LoadFont(const char* filePath, int fontSize);
138
139 private:
140 Window* window;
141 int windowWidth, windowHeight;
142 ShaderProgram* hudImageShader;
143 ShaderProgram* hudProgressBarShader;
144 ShaderProgram* hudTextShader;
145 float fontHeight;
147 VertexArrayObject textVao;
148
149 // lists of hud elements
150 std::vector<HUD_IMAGE*> hudImageElements;
151 std::vector<HUD_PROGRESS_BAR*> hudBarElements;
152 std::vector<HUD_TEXT*> hudTextElements;
153
155 struct Character {
156 unsigned int TextureID;
157 glm::ivec2 Size;
158 glm::ivec2 Bearing;
159 unsigned int Advance;
160 };
161
162 std::map<char, Character> Characters;
163 };
164}
Class to render HUD elements on the screen.
Definition hud.h:15
HUD(Window *window)
Definition hud.cpp:18
void LoadFont(const char *filePath, int fontSize)
Definition hud.cpp:321
HUD_TEXT * GetHUDTextByName(const std::string &name)
Definition hud.cpp:137
HUD_IMAGE * NewHUDImage(std::string name, glm::vec2 position, glm::vec2 scale, float rotation, Texture *texture)
Definition hud.cpp:52
HUD_IMAGE * GetHUDImageByName(const std::string &name)
Definition hud.cpp:119
void RemoveHUDImage(HUD_IMAGE *imageToRemove)
Definition hud.cpp:146
HUD_TEXT * NewHUDText(std::string name, glm::vec2 position, glm::vec2 scale, float rotation, std::string textContent, glm::vec3 colour)
Definition hud.cpp:102
~HUD()=default
HUD manager destructor.
HUD_PROGRESS_BAR * GetHUDProgressBarByName(const std::string &name)
Definition hud.cpp:128
void RemoveHUDText(HUD_TEXT *textToRemove)
Definition hud.cpp:160
HUD_PROGRESS_BAR * NewHUDProgressBar(std::string name, glm::vec2 position, glm::vec2 scale, float rotation, Texture *underTexture, Texture *progressTexture, float minValue, float maxValue, float value)
Definition hud.cpp:71
void RemoveHUDProgressBar(HUD_PROGRESS_BAR *progressBarToRemove)
Definition hud.cpp:153
void Render()
Renders all active HUD elements.
Definition hud.cpp:167
A linked OpenGL program.
Definition shaderProgram.h:16
Texture base class.
Definition texture.h:20
Definition vao.h:8
Definition window.h:13
Definition hud.h:19
float rotation
Rotation of the image, in radians.
Definition hud.h:26
std::string name
Name of the HUD element.
Definition hud.h:21
bool active
Flag to indicate if currently active.
Definition hud.h:22
Texture * texture
Texture to display.
Definition hud.h:23
glm::vec2 scale
Scale of the image.
Definition hud.h:25
glm::vec2 position
2D position in screen coordinates
Definition hud.h:24
Definition hud.h:31
Texture * progressTexture
Texxture rendered on the progress bar, according to current progress value.
Definition hud.h:36
float value
Current value of the progress bar.
Definition hud.h:43
float minValue
Minimum value for the progress bar.
Definition hud.h:41
float rotation
Rotation of the progress bar, in radians.
Definition hud.h:39
glm::vec2 position
2D position in screen coordinates
Definition hud.h:37
bool active
Flag to indicate if currently active.
Definition hud.h:34
std::string name
Name of the HUD element.
Definition hud.h:33
glm::vec2 scale
Scale of the progress bar.
Definition hud.h:38
float maxValue
Maximum value for the progress bar.
Definition hud.h:42
Texture * underTexture
Textured rendere underneath the progress bar.
Definition hud.h:35
Class to display text on the screen.
Definition hud.h:47
std::string name
Name of the HUD element.
Definition hud.h:49
glm::vec2 position
2D position in screen coordinates
Definition hud.h:51
float rotation
Rotation of the text, in radians.
Definition hud.h:53
bool active
Flag to indicate if currently active.
Definition hud.h:50
glm::vec3 colour
Colour of the text, in RGB.
Definition hud.h:55
glm::vec2 scale
Scale of the text.
Definition hud.h:52
std::string textContent
The text string to be displayed.
Definition hud.h:54