19#include <unordered_map>
61 Font(
const std::string &filepath,
unsigned int font_size = 48);
81 inline std::shared_ptr<renderer::Texture>
get_atlas()
const {
return m_atlas; }
107 unsigned int m_font_size;
113 std::shared_ptr<renderer::Texture> m_atlas;
116 std::unordered_map<char, Glyph> m_glyphs;
123 void generate_atlas(
const std::string &filepath);
138 static FontManager &
get();
148 std::shared_ptr<Font>
load(
const std::string &name,
const std::string &filepath,
unsigned int font_size = 48);
156 std::shared_ptr<Font>
get_font(
const std::string &name);
164 bool exists(
const std::string &name)
const;
172 FontManager() =
default;
173 ~FontManager() =
default;
176 static std::unordered_map<std::string, std::shared_ptr<Font>> s_fonts;
void clear()
Clear all cached fonts.
Definition font.cpp:193
std::shared_ptr< Font > load(const std::string &name, const std::string &filepath, unsigned int font_size=48)
Load a font or get it from cache.
Definition font.cpp:164
static FontManager & get()
Get the singleton instance.
Definition font.cpp:159
std::shared_ptr< Font > get_font(const std::string &name)
Get a previously loaded font.
Definition font.cpp:181
bool exists(const std::string &name) const
Check if a font exists in the cache.
Definition font.cpp:189
Font(const std::string &filepath, unsigned int font_size=48)
Load a font from file.
Definition font.cpp:23
~Font()=default
Destructor.
std::shared_ptr< renderer::Texture > get_atlas() const
Get the texture atlas containing all glyphs.
Definition font.hpp:81
const Glyph & get_glyph(char c) const
Get glyph metadata for a character.
Definition font.cpp:137
unsigned int get_font_size() const
Get the font size in pixels.
Definition font.hpp:88
float get_line_height() const
Get the line height for this font.
Definition font.hpp:95
float measure_text(const std::string &text) const
Calculate the width of a text string in pixels.
Definition font.cpp:147
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12
Glyph metadata for a single character.
Definition font.hpp:30
float advance
Horizontal offset to advance to next glyph.
Definition font.hpp:44
glm::vec2 bearing
Offset from baseline to top-left of glyph.
Definition font.hpp:41
glm::vec2 tex_coord_max
UV coordinates in texture atlas (max).
Definition font.hpp:35
glm::vec2 size
Size of glyph in pixels.
Definition font.hpp:38
glm::vec2 tex_coord_min
UV coordinates in texture atlas (min).
Definition font.hpp:32
Texture class for managing OpenGL textures.