wgpu-text
wgpu-text is a wrapper over glyph-brush for fast and easy text rendering in wgpu. It accepts .otf and .ttf fonts.
This project was inspired by and is similar to wgpu_glyph but has additional features and is more straightforward. Also, there is no need to include glyph-brush in your project.
Some features are directly implemented from glyph-brush, so it's recommended to go through Section docs and Section examples for better understanding of managing and adding text.
Installation
Add the following to your Cargo.toml file:
[]
= "0.8.0"
Usage
use ;
let brush = using_font_bytes.unwrap
/* .initial_cache_size((16_384, 16_384))) */ // use this to avoid resizing cache texture
.build;
// Directly implemented from glyph_brush.
let section = default.add_text;
// on window resize:
brush.resize_view;
// window event loop:
RedrawRequested =>
Examples
For more detailed examples, look through examples.
cargo run --example <example-name>
Run examples with --release for accurate performance.
Features
Besides basic text rendering and glyph-brush features, some features add customization:
- builtin matrix - default matrix for orthographic projection (feel free to use it for creating custom matrices)
- custom matrix - grants the ability to provide a custom matrix for purposes of custom view, rotation, etc. (the downside is that it applies to all rendered text)
- depth testing - by adding a z coordinate, text can be set on top or below other text (if enabled). Watch out for the queueing order when queueing text sections. You should queue them from the furthest to the closest (according to the z coordinate, bigger the z, more further it is).
Future
- wgpu stuff: maybe change to StagingBelt instead of Queue
Contributing
All contributions are welcome.