Crates.io | glyph_brush |
lib.rs | glyph_brush |
version | 0.7.11 |
source | src |
created_at | 2018-09-01 19:53:43.026939 |
updated_at | 2024-10-20 09:19:22.335245 |
description | Fast cached text render library using ab_glyph |
homepage | |
repository | https://github.com/alexheretic/glyph-brush |
max_upload_size | |
id | 82546 |
size | 283,776 |
Fast caching text render library using ab_glyph. Provides render API agnostic rasterization & draw caching logic.
Makes extensive use of caching to optimise frame performance.
The crate is designed to be easily wrapped to create a convenient render API specific version, for example gfx-glyph.
use glyph_brush::{ab_glyph::FontArc, BrushAction, BrushError, GlyphBrushBuilder, Section, Text};
let dejavu = FontArc::try_from_slice(include_bytes!("../../fonts/DejaVuSans.ttf"))?;
let mut glyph_brush = GlyphBrushBuilder::using_font(dejavu).build();
glyph_brush.queue(Section::default().add_text(Text::new("Hello glyph_brush")));
glyph_brush.queue(some_other_section);
match glyph_brush.process_queued(
|rect, tex_data| update_texture(rect, tex_data),
|vertex_data| into_vertex(vertex_data),
) {
Ok(BrushAction::Draw(vertices)) => {
// Draw new vertices.
}
Ok(BrushAction::ReDraw) => {
// Re-draw last frame's vertices unmodified.
}
Err(BrushError::TextureTooSmall { suggested }) => {
// Enlarge texture + glyph_brush texture cache and retry.
}
}
Have a look at
cargo run --example opengl --release