A crate for drawing text with SDL2 using fontdue for rasterization.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jens Pitkänen 6c2d02c8af Bump to dev version 0.2.0-alpha.0 1 month ago
.github/workflows Remove linux and windows tests from CI 1 month ago
examples Add color to rendering and write docs 1 month ago
misc Add color to rendering and write docs 1 month ago
src Use Texture::update instead of Texture::with_lock 1 month ago
.gitignore Initial commit 1 month ago
Cargo.toml Bump to dev version 0.2.0-alpha.0 1 month ago
LICENSE.md Initial commit 1 month ago
README.md Add GitHub Actions badge 1 month ago



docs.rs badge crates.io badge GitHub Actions badge

A crate for drawing text with sdl2::render, using fontdue for rasterization. This library is glue-code, all the good parts are from the aforementioned libraries.

The motivation for this crate is to allow easier, rustier, and better quality text rendering in projects that use SDL2's render module, compared to sdl2_ttf.

Note that fontdue is already a "full solution to text rendering", it's a very application-facing crate. This crate exists so that I don't need to write a text rendering cache for each SDL2 project I work on, and that part isn't implemented in fontdue probably because it varies based on rendering technology. This is a solution for fontdue + SDL2.


Read the docs on docs.rs.

Compared to sdl2_ttf

This library draws each glyph as its own quad, from a single gylph cache texture. This is very fast on modern GPUs, as it can be done in a single draw call. Per-text-area caching can still be achieved by rendering this library's results into a render texture.

Performance and shortcomings

Reserving a spot on the glyph cache texture is currently proportional to the amount of previously allocated glyphs, so it gets slower over time. Some ad-hoc testing shows about 20 microseconds per glyph in release, up to 200 microseconds in debug, for a few paragraphs at different sizes. This rarely affects overall performance badly however, since this only needs to be done once per character/size/color/font combo. But there is still a lot of room for optimization.

Currently the crate is still a work in progress, so there are a few missing features:

  • The glyph cache texture isn't resized on the fly, the texture is always 1024x1024.
  • Unused glyphs can't be overwritten, every glyph that gets written will exist in the cache forever.

Removing unused glyphs (and detecting them, for that matter) may be too performance intensive in the end, so I may release a 1.0 after I implement on-the-fly texture resizing. Manual clearing of the cache might also be added, though the usefulness of that is questionable, as you could simply create a new FontTexture for a similar effect.


This mostly shows off fontdue (the text rasterization) and SDL2 (the window and rendering), but I think rendering crates should have screenshots for first impressions. This screenshot was taken of the testbed.rs example.

Screenshot of some text from Wikipedia rendered using this crate.


This library can be used under the terms of the MIT license.