Crates.io | kaku |
lib.rs | kaku |
version | 0.1.1 |
source | src |
created_at | 2024-07-15 14:01:19.810829 |
updated_at | 2024-07-26 04:11:05.615321 |
description | A text rendering crate for wgpu using signed distance fields |
homepage | |
repository | https://github.com/villuna/kaku |
max_upload_size | |
id | 1303885 |
size | 147,854 |
A text rendering crate for rust+wgpu, with the ability to use signed distance fields.
Without going into details, signed distance fields are a way of representing a shape (such as a character in a font) in a way that allows for high quality upscaling, reducing memory usage. It also allows you to render certain effects such as outlines in a way that is very performant.
When you create a Text object with kaku, it has to generate the signed distance field for every new glyph in the text. These fields are cached, so this only ever has to happen once per glyph per font. Calculating this texture takes a small but not-insignificant amount of time (on the order of 1ms in my testing, but this will depend on your computer and on the glyph), so if this is a problem, you can also render text without sdf.
You can also pre-compute the distance fields for characters you know that you will draw. For example, for an English-language video game, you could cache all alphanumeric characters in the startup loading screen.
Once a text object is created, rendering it to the screen is about as fast with sdf as it is without.
Here is a screenshot of the demo example, showing some of the things kaku can do:
This example shows the same text: