Text
The text2d and text3d components: keys, outline and shadow, markup, script calls, measuring, bitmap fonts and what a block costs.
On this page
text2d and text3d draw text in the scene. The widget layer draws text on
the screen.
One shaper and one glyph atlas serve both: bidirectional text, Arabic joining, CJK and Thai line breaking and the project's font chain work the same in a panel and in the world.

Two components
text2d draws in the 2D pass, sized like a sprite. text3d draws in the 3D
pass on a quad facing the camera. They take the same keys, and text3d adds a
few.
[[nodes]]
id = "sign"
name = "Sign"
[nodes.transform]
position = [0.0, 1.6, 0.0]
[nodes.text3d]
text = "A score on a sign"
font_size = 64
color = [1.0, 0.85, 0.3, 1.0]
pixels_per_unit = 110
text_style = { outline_size = 3.0, outline_color = [0.1, 0.05, 0.0, 1.0] }
| Key | What it does |
|---|---|
text |
The string drawn |
text_key |
A key in the project's strings, re-read every frame; it wins over text |
font |
The face: a file such as fonts/Inter.ttf, or a font asset. Empty takes the theme's default font |
font_size, font_weight, font_style |
Height in font pixels, 100–900, and normal, italic or oblique |
text_style |
Line height, spacing, outline and shadow: a text_style asset, or one written inline |
color, text_align |
Tint, and where the block sits across the node's origin |
max_width, max_height, max_lines |
Font pixels the lines wrap and stop at, and the most lines kept |
line_break, tab_width |
Where a wrapped line may break, and the spaces between tab stops |
truncate, truncate_at |
End a cut block with an ellipsis, and which part it stands in for |
markup |
Read the text as markup |
material |
What every layer draws with, reading the glyph atlas as its texture |
pixels_per_unit |
Font pixels to one world unit |
- Doubling
font_sizeandpixels_per_unittogether keeps the on-screen size and doubles the sharpness. text3daddsbillboard,cast_shadow,receive_shadows,light_layers,render_layersandsegmentation_id.billboardturns the block to the camera every frame. Off, the block stays in the node's own plane.- A material's
[surface]says whether the glyphs are cut out (alpha = "mask"), which sides of atext3ddraw and whether the scene hides it.
Outline and shadow
text_style holds what dresses a text past its font. Write it inline, as above,
or keep it in a file under text_styles/ and name its path.
# text_styles/sign.toml
type = "text_style"
line_height = 1.2 # baselines apart, as a multiple of the size
letter_spacing = 1.0 # extra pixels between glyphs
outline_size = 3.0
outline_color = [0.1, 0.05, 0.0, 1.0]
shadow_offset_x = 2.0
shadow_offset_y = 2.0
shadow_color = [0.0, 0.0, 0.0, 0.5]
- One file serves every
text2d,text3dand widget naming it. underline,overlineandstrikethroughdraw lines with the glyphs, each with a_colorkey of its own.
Markup
With markup = true the text takes the same tags as a widget's label: [b],
[i], [color=#7fd4ff], [wave amp= freq=], [center], [right] and an
inline [img=…]. A coloured run keeps its own colour over the block's.
Two more tags answer the pointer, which only a widget label can do:
[url=target] calls that label's on_link with the target, and
[hint=text] shows the text while the pointer rests on the span.
From a script
let node = scene::get_node("Hud/Score");
node.text2d.text = "{self.score}";
let p = self.node.transform.global_position();
render::draw_text_3d(p.x, p.y + 2.0, p.z, "over a character", render::TextOptions { font_size: 32.0, text_align: "center" });
render::draw_text_2d(0.0, 3.0, "in the 2D pass", render::TextOptions { font_size: 24.0 });
text2d.textandtext3d.textchange what a node draws.draw_text_2danddraw_text_3ddraw with no node, for one frame. Neither is recorded: a replay re-runs the script that drew.- The editor's Rig tool labels bones with
draw_text_3d.
Measuring
let size = render::text_size("measure me", render::TextOptions { font_size: 32.0 }); // size.x, size.y
- Returns the width and height a string shapes to, in font pixels.
- Measured against the project's fonts and the bundled ones, never the machine's. Every platform answers the same.
- A width is presentation. A script that writes one into state puts
presentation in the digest. The same holds for a
kind = "text"mesh, whose vertices are geometry with colliders fitted to them.
Bitmap fonts
[nodes.text2d]
text = "SCORE 1200"
font = "fonts/pixel.fnt"
font_size = 32
fonttakes an AngelCode.fntas it takes any face file. The engine reads the page beside it and every glyph's box, then lays the text out by advance and kerning.- Only the text form of a
.fntis read, not the binary one. - Nothing is shaped: a bitmap font has one glyph per character and no contextual forms.
- The page is copied into the same atlas as the rasterised glyphs. A bitmap glyph and a vector one are one texture and one draw.
Editing in the viewport
Double-click a text2d or text3d in the Scene workspace to open a field over
it. Enter keeps the text, Escape drops it.
Cost
- A block is one mesh per colour it draws in, plus one for the outline and one for the shadow.
- Glyphs are rasterised at the size the block covers on screen, quantized to buckets 8.7% apart.
- Walking towards a sign re-shapes it a few times. Two blocks at nearly the same size share their glyphs.
- A glyph is scaled by up to 8.7% between buckets.
examples/text
has all of it.