wgpu-text is a wrapper over glyph-brush for fast and easy text rendering in wgpu.
This project was inspired by and is similar to wgpuglyph_, but has additional features and is simpler. Also there is no need to include glyph-brush in your project.
Some features are directly implemented from glyph-brush so you should go trough Section docs and Section examples for better understanding of managing and adding text.
Add the following to your Cargo.toml
file:
toml
[dependencies]
wgpu_text = "0.6.3"
```rust use wgpu_text::section::{Section, Text, Layout, HorizontalAlign};
let brush = wgputext::BrushBuilder::usingfontbytes(font).unwrap() /* .initialcachesize((1024, 1024))) */ // use this to avoid resizing cache texture /* .withdepth_testing(true) */ // enable/disable depth testing .build(&device, &config);
// Directly implemented from glyphbrush. let section = Section::default() .addtext(Text::new("Hello World")) .withlayout(Layout::default().halign(HorizontalAlign::Center));
// on window resize: brush.resize_view(config.width as f32, config.height as f32, &queue);
// window event loop: winit::event::Event::RedrawRequested(_) => { // Has to be queued every frame. brush.queue(§ion);
let text_buffer = brush.draw(&device, &view, &queue);
// Has to be submitted last so text won't be overlapped.
queue.submit([some_other_encoder.finish(), text_buffer]);
frame.present();
}
```
For more detailed examples look trough examples.
* cargo run --example <example-name>
Run examples with --release
for true performance.
Besides basic text rendering and glyph-brush features, there are some features that add customization:
builtin matrix - default matrix for orthographic projection, feel free to use it for creating custom matrices
custom matrix - ability of providing a custom matrix for purposes of custom view, rotation... (the downside is that it applies to all rendered text)
depth testing - by adding z coordinate, text can be set on top or below other text (if enabled)
All contributions are welcome.