7#include <unordered_map>
12#include "../../types/types.hpp"
13#include "../texture.hpp"
14#include "../../util/color.hpp"
15#include "../../shapes/shapes.hpp"
35 std::unordered_map<uint32_t, Character>
glyphs;
45 Font(FT_Face f,
int h,
const std::string& p)
71 std::unordered_map<std::string, std::unique_ptr<Font>>
fonts;
Singleton that loads fonts and renders text via FreeType.
Definition text_renderer.hpp:62
void renderText(Font *font, const std::string &text, Vector3 pos, float scale, const Color &color)
Draws a text string at a position.
Definition text_renderer.cpp:129
bool valid
Whether the renderer initialized successfully.
Definition text_renderer.hpp:74
TextRenderer()
Constructs the renderer and initializes FreeType.
Definition text_renderer.cpp:201
bool init_freetype()
Initializes the FreeType library.
Definition text_renderer.cpp:42
std::unordered_map< std::string, std::unique_ptr< Font > > fonts
Loaded fonts keyed by path.
Definition text_renderer.hpp:71
~TextRenderer()
Releases FreeType resources.
Definition text_renderer.cpp:219
Font * loadFont(std::string path, int height=40)
Loads a font from disk (or returns the cached one).
Definition text_renderer.cpp:51
bool loadGlyph(Font *font, uint32_t cp)
Rasterizes and caches a single glyph.
Definition text_renderer.cpp:93
static TextRenderer * getInstance()
Returns the singleton instance.
Definition text_renderer.cpp:197
static TextRenderer * instance
Singleton instance.
Definition text_renderer.hpp:64
void clearGlyphCache(Font *font)
Clears the cached glyphs for a font.
Definition text_renderer.cpp:37
FT_Library ft
FreeType library handle.
Definition text_renderer.hpp:65
void setFontHeight(Font *font, int heightIn)
Changes a font's pixel height and clears its glyph cache.
Definition text_renderer.cpp:83
Vector2 measureText(Font *font, const std::string &text, float scale)
Measures the rendered size of a text string.
Definition text_renderer.cpp:169
Wraps an OpenGL texture object.
Definition texture.hpp:12
Definition audiomanager.cpp:4
std::vector< uint32_t > utf8_to_codepoints(const std::string &str)
Decodes a UTF-8 string into a list of Unicode codepoints.
Definition text_renderer.cpp:9
A single cached glyph: its texture and layout metrics.
Definition text_renderer.hpp:21
unsigned int advance
Horizontal advance to the next glyph (in 1/64 px).
Definition text_renderer.hpp:27
int width
Glyph bitmap width in pixels.
Definition text_renderer.hpp:23
Texture texture
Texture holding the rasterized glyph.
Definition text_renderer.hpp:22
int bearingY
Vertical offset from the baseline to the glyph's top edge.
Definition text_renderer.hpp:26
int height
Glyph bitmap height in pixels.
Definition text_renderer.hpp:24
int bearingX
Horizontal offset from the origin to the glyph's left edge.
Definition text_renderer.hpp:25
RGBA color stored as normalized floating-point components.
Definition color.hpp:12
A loaded font face plus its cache of rasterized glyphs.
Definition text_renderer.hpp:33
std::unordered_map< uint32_t, Character > glyphs
Cache of glyphs keyed by codepoint.
Definition text_renderer.hpp:35
std::string path
Path the font was loaded from.
Definition text_renderer.hpp:37
Font(FT_Face f, int h, const std::string &p)
Constructs a font wrapper around a FreeType face.
Definition text_renderer.hpp:45
int height
Pixel height the face is set to.
Definition text_renderer.hpp:36
FT_Face face
Underlying FreeType face handle.
Definition text_renderer.hpp:34
Two-component floating-point vector.
Definition vector2.hpp:13
Three-component floating-point vector.
Definition vector3.hpp:13