-
Notifications
You must be signed in to change notification settings - Fork 3
Docs Fonts
This page provides information how to access and use font objects. (Introduced in: v0.2.0)
Fonts in the engine are simple objects with basic information about available glyphs and font atlasses. The data provided is constant and can be used however you like.
Using ice::Font
directly in most places will not allow you to render text however it's can provide some helpful information about glyph sizes.
Currently fonts are utilized in the UI system and 'Glyphs' render trait using the name of a specific font asset.
Rendering text is done via the 'Glyphs' trait, which provides ice::DrawTextCommand
structure. A pointer to a constant version of this object is then sent to the frame and processed.
- Add the base_framework library to your dependnecies.
- Add the
ice::Constant_TraitName_RenderGlyphs
trait to your renderer world template. - Add the
ice::Constant_GfxStage_DrawGlyphs
stage to your graphics pass definition.
The object requires to provide the position
, text
and font
values, and optionally font_size
which defaults to 16
.
Definition: DrawTextCommand
//! \project framework_base
//! \file game_render_traits.hxx
//! \namespace ice
struct DrawTextCommand
{
ice::vec2u position;
ice::Utf8String text;
ice::Utf8String font;
ice::u32 font_size = 16;
};
Fields:
-
position : ice::vec2u
- Takes a absolute position in pixels where the text should be located on X and Y axis.- The anhor point is on the bottom left, and the text grows upwards.
-
text : ice::Utf8String
- The text value we want to render.- If a given font does not support a specific character it will be ignored and the next valid character will be placed on that position.
-
font : ice::Utf8String
- The name of the font we want to use to draw the text. -
font_size : ice::u32
- The size of the glyphs we want to draw. (default: 16)
The command is sent using a shard (ice::Shard_DrawTextCommand
) on the target engine frame.
Example:
// The objects needs to live during the whole frame. We use a static value, but other ways are also fine.
static ice::DrawTextCommand const hello_world{
.position = { 50, 50 },
.text = u8"Hello, World!",
.font = u8"calibri",
.font_size = 24
};
ice::shards::push_back(
current_frame.shards(),
ice::Shard_DrawTextCommand | &hello_world
);