Skip to content

Conversation

@ickshonpe
Copy link
Contributor

@ickshonpe ickshonpe commented Jan 29, 2026

Objective

Lightweight immediate mode stroke fonts text gizmo implementation.

Fixes #16490

Solution

New bevy_gizmos module text containing functions text and text_2d implemented for GizmoBuffer.

The text function has parameters:

  • isometry: Into<Isometry3d>: defines the translation and rotation of the text.
  • text: &str: the text to be drawn.
  • size: f32: the height of the glyphs.
  • anchor: Vec2: anchor point relative to the center of the text.
  • color: Into<Color>: the color of the text.

text_2d is the same, except the isometry is Into<Isometry2d>.

The glyph set is limited to ASCII characters from 33 to 126.

The text rendering uses the Simplex Hershey font:
https://en.wikipedia.org/wiki/Hershey_fonts
https://paulbourke.net/dataformats/hershey/

The static font data is in the bevy_gizmos::text_font module.
Hershey fonts are public domain and don't require any attribution.

The text geometry isn't retained but since it's so simple, it's still much faster than the retained Cosmic Text version I wrote initially. That might not be the case if it's used to display whole pages of text, but this isn't intended for that.

Glyphs are drawn using linestrips.

I think this would be better with a monospaced font but it's using a proportional font atm.

Only left-to-right, left justified text is supported.

I left out line height and justify options, they are trivial to add but I'm not sure if we need them. Maybe they could be added to the gizmo config later. Could make a case for moving the size parameter to the config as well.

Testing

Example displaying text gizmos rotating in 3d

cargo run --example 3d_text_gizmos

Example displaying all the glyphs from the text gizmos font:

cargo run --example text_gizmos_font

Larger example with lots of text and an FPS counter:

cargo run --example 2d_text_gizmos

Showcase

tg-example 2d_gizmos hello_text_gizmos all_glyphs text-gizmos-3d

@ickshonpe ickshonpe added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen A-Gizmos Visual editor and debug gizmos A-Text Rendering and layout for characters D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 29, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering (2026 Proposal) Jan 29, 2026
@alice-i-cecile alice-i-cecile added the M-Release-Note Work that should be called out in the blog due to impact label Jan 29, 2026
@alice-i-cecile
Copy link
Member

Agreed on monospace preference. What are the requirements when selecting a new font candidate for this?

@ickshonpe
Copy link
Contributor Author

Agreed on monospace preference. What are the requirements when selecting a new font candidate for this?

Not much really, just have to choose a font and embed the font data. There are some hershey font collections online:
http://www.whence.com/hershey-fonts/

Need to go bed though, I'll have a look into it tomorrow evening.

@alice-i-cecile alice-i-cecile added D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes and removed D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Gizmos Visual editor and debug gizmos A-Rendering Drawing game state to the screen A-Text Rendering and layout for characters C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Release-Note Work that should be called out in the blog due to impact S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: No status
Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Text Gizmos

4 participants