29 个版本
0.9.0 | 2024 年 7 月 19 日 |
---|---|
0.8.7 | 2024 年 3 月 29 日 |
0.8.5 | 2023 年 10 月 27 日 |
0.8.3 | 2023 年 7 月 24 日 |
0.4.0 |
|
#17 在 渲染 中
245 每月下载量
用于 pseudo_term
36KB
679 代码行
wgpu-text
wgpu-text
是 glyph-brush
的包装,用于通过 wgpu
快速且简单地渲染文本。它支持 .otf 和 .ttf 字体。

该项目受到 wgpu_glyph
的启发,并与之类似,但具有更多功能且更直观。此外,无需在项目中包含 glyph-brush。
由于 glyph-brush crate 被重新导出,且高度依赖,建议阅读 Section 文档 和 Section 示例 以更好地理解管理和添加文本。
安装
将以下内容添加到您的 Cargo.toml
文件中
[dependencies]
wgpu_text = "0.9.0"
用法
use wgpu_text::{glyph_brush::{Section as TextSection, Text}, BrushBuilder, TextBrush};
let brush = BrushBuilder::using_font_bytes(font).unwrap()
/* .initial_cache_size((16_384, 16_384))) */ // use this to avoid resizing cache texture
.build(&device, config.width, config.height, config.format);
// Directly implemented from glyph_brush.
let section = TextSection::default().add_text(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.queue(&device, &queue, [§ion, ...]).unwrap();
{
let mut rpass = encoder.begin_render_pass(...);
brush.draw(&mut rpass);
}
queue.submit([encoder.finish()]);
frame.present();
}
示例
有关更多详细示例,请参阅 示例。
cargorun --example <example-name>
使用 --release
运行示例以获取准确性能。
功能
除了基本的文本渲染和 glyph-brush 功能外,一些功能增加了自定义
- 内置矩阵 - 正交投影的默认矩阵(您可以自由使用它来创建自定义矩阵)
- 自定义矩阵 - 允许提供自定义矩阵以实现自定义视图、旋转等目的(缺点是它适用于所有渲染文本)
- 深度测试 - 通过添加 z 坐标,文本可以设置为位于其他文本之上或之下(如果启用)。请注意在排队 文本段落 时的队列顺序。您应该从最远到最近(根据 z 坐标,越大表示越远)排队。
贡献
欢迎所有类型的贡献。
依赖关系
~12–43MB
~686K SLoC