2D_Game_Engine
Loading...
Searching...
No Matches
textrenderer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <vertexbuffer.hpp>
5#include <vertexarray.hpp>
6#include <shader.hpp>
7
8#include <ft2build.h>
9#include FT_FREETYPE_H
10
11inline constexpr unsigned int CH_LIMIT=400;
12inline constexpr unsigned int CH_NUM=128;
13
15public:
16 TextRenderer(): m_Loaded(false),m_Characters(nullptr),m_Transforms(nullptr),m_ToRender(nullptr),m_FontPath(100,'\0'),m_GlyphSize(0),m_Fixed(false){}
20 TextRenderer(const std::string &font_path,float glyph_size,bool fixed);
24 TextRenderer(const std::string &font_path,float glyph_size,bool fixed,uint32_t id);
26
36 void DrawText(const std::string &text,float x,float y,float scale,int layer,Vec3 color);
37
47 void _DrawText(const std::string &text,float x,float y,float scale,Vec3 color);
53 std::pair<float,float> GetTextSize(std::string text,float scale);
54
55 inline void UpdateProjMat(glm::mat4 &proj){
56 if(m_Loaded){
57 m_Shader.Bind();
58 m_Shader.SetUniformMat4fv("u_PM",glm::value_ptr(proj),1);
59 }
60 }
61
62private:
63 friend class SceneSerializer;
64 friend class FontManager;
65
66 struct Character{
67 unsigned int TexID; // ID of the glyph texture
68 glm::ivec2 Size; // Size of glyph
69 glm::ivec2 Bearing; // Offset from baseline to left/top of glyph
70 unsigned int Advance; // Horizontal offset to advance to next glyph
71 };
72
73 FT_Library m_FT;
74 FT_Face m_Face;
75
76 VertexBuffer m_VBO;
77 VertexArray m_VAO;
79 Shader m_Shader;
80
81 unsigned int m_TextureArrayID;
82 Character *m_Characters;
83 glm::mat4 *m_Transforms;
84 int *m_ToRender;
85
86 std::string m_LoadedFontPath;
87 float m_LoadedGlyphSize;
88
89 bool m_Loaded;
90
91 void Init(const std::string &font_path,float glyph_size,bool fixed);
92 void Render(int num_characters);
93
94public:
95 uint32_t m_ID;
96 std::string m_FontPath;
98 bool m_Fixed;
99};
void Bind() const
Definition shader.cpp:68
void SetUniformMat4fv(const std::string &name, float *proj, unsigned int num_elem)
Definition shader.cpp:136
std::pair< float, float > GetTextSize(std::string text, float scale)
void DrawText(const std::string &text, float x, float y, float scale, int layer, Vec3 color)
void UpdateProjMat(glm::mat4 &proj)
void _DrawText(const std::string &text, float x, float y, float scale, Vec3 color)
std::string m_FontPath
constexpr unsigned int CH_LIMIT
constexpr unsigned int CH_NUM