Fonts
Fonts are rasterized to atlas textures and rendered by TextPass. They are registered with ResourceManager as FontDescriptors and loaded asynchronously like other resource types.
Registration
auto res = ResourceManager::get();
res->register_font(FontDescriptor::create(
"roboto",
"fonts/Roboto-Regular.ttf"_engine,
/* atlas_size */ 512,
/* base_size */ 48
));Descriptor Fields
| Field | Type | Description |
|---|---|---|
id | std::string | Unique identifier |
path | Path | Engine-relative path to the .ttf / .otf file |
atlas_size | uint32_t | Width and height of the generated texture atlas in pixels |
base_size | uint32_t | Point size used when rasterizing glyphs into the atlas |
Larger base_size values produce sharper text at large display sizes but consume more atlas space. A 512×512 atlas at 48pt covers the full printable ASCII range.
Uploading
res->load_from_descriptors<FontDescriptor>(RendererBackend::OpenGL);During upload, the font file is parsed, glyphs are rasterized to a CPU-side bitmap, and the result is uploaded to GPU as a Texture2D atlas. Per-glyph metrics (advance, bearing, UV rect) are stored alongside the atlas handle.
Rendering Text
Text is rendered by adding a text entity to the scene:
// In Scene::start()
auto* label = add_entity<Text>("FPSLabel");
label->content = "Hello, Astra!";
label->font_id = "roboto";
label->position = glm::vec2(16.0f, 16.0f);
label->scale = 1.0f;
label->color = glm::vec4(1.0f);TextPass collects all text entities each frame, batches their quads per font atlas, and issues a single draw call per atlas.
Atlas Layout
Multi-Font Scenes
Each unique font_id maps to a separate atlas. TextPass sorts entities by font before batching, so switching fonts mid-scene does not break instancing within a single font.
Supported Formats
| Format | Support |
|---|---|
TrueType (.ttf) | Supported |
OpenType (.otf) | Supported |
| Bitmap fonts | Not supported |