wgpu-text

Build Status Licence crates.io Documentation

wgpu-text is a wrapper over glyph-brush for fast and easy text rendering in wgpu. It supports .otf and .ttf fonts.

Library Lorem Ipsum Showcase

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.

Since the crate glyph-brush is reexported and being heavily dependent on, 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:

toml [dependencies] wgpu_text = "0.8.3"

Usage

```rust use wgputext::glyphbrush::{Section, Text, Layout, HorizontalAlign, BrushBuilder};

let brush = BrushBuilder::usingfontbytes(font).unwrap() /* .initialcachesize((16384, 16384))) */ // use this to avoid resizing cache texture .build(&device, &config);

// Directly implemented from glyphbrush. let section = Section::default().addtext(Text::new("Hello World"));

// on window resize: brush.resize_view(config.width as f32, config.height as f32, &queue);

// window event loop: winit::event::Event::RedrawRequested(_) => { // Before are created Encoder and frame TextureView.

    // Crashes if inner cache exceeds limits.
    brush.process_queued(&device, &queue, vec![&section, ...]).unwrap();

    {
        let mut rpass = encoder.begin_render_pass(...);
        brush.draw(&mut rpass);
    }

    queue.submit([encoder.finish()]);
    frame.present();
}

```

Examples

For more detailed examples, look through examples.

Run examples with --release for accurate performance.

Features

Besides basic text rendering and glyph-brush features, some features add customization:

Contributing

All contributions are welcome.