wgpu text
v0.8.5
wgpu-text是wgpu的快速简便文字渲染的glyph-brush的包装。它支持.otf和.ttf字体。

该项目的灵感来自于wgpu_glyph ,但具有其他功能,并且更简单。另外,无需在您的项目中包括字形刷。
由于重新审查了字形灌木板条箱并严重依赖于尺寸,因此建议您通过部分文档和部分示例,以更好地理解管理和添加文本。
将以下内容添加到您的Cargo.toml文件:
[ dependencies ]
wgpu_text = " 0.9.1 " 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 , [ & section , .. . ] ) . unwrap ( ) ;
{
let mut rpass = encoder . begin_render_pass ( .. . ) ;
brush . draw ( & mut rpass ) ;
}
queue . submit ( [ encoder . finish ( ) ] ) ;
frame . present ( ) ;
} 有关更详细的示例,请浏览示例。
cargo run --example <example-name>运行示例与--release以进行准确的性能。
除了基本的文本渲染和字形刷功能外,某些功能还增加了自定义:
欢迎各种贡献。