wgpu text
v0.8.5
wgpu-text เป็น wrapper เหนือ glyph-brush สำหรับการแสดงข้อความ ที่ง่าย และ ง่ายดาย โดย wgpu รองรับแบบอักษร . OTF และ . TTF

โครงการนี้ได้รับแรงบันดาลใจจากและคล้ายกับ wgpu_glyph แต่มีคุณสมบัติเพิ่มเติมและตรงไปตรงมามากขึ้น นอกจากนี้ไม่จำเป็นต้องรวม Glyph-brush ในโครงการของคุณ
เนื่องจากลัง Glyph-brush ถูก ส่งออกใหม่ และต้องพึ่งพาอย่างมากจึงแนะนำให้ผ่านเอกสารส่วนและส่วนตัวอย่างเพื่อความเข้าใจที่ดีขึ้นในการจัดการและเพิ่มข้อความ
เพิ่มสิ่งต่อไปนี้ในไฟล์ 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 เพื่อประสิทธิภาพที่แม่นยำ
นอกเหนือจากการเรนเดอร์ข้อความพื้นฐานและคุณสมบัติ การพู่กันของร่ายมนตร์ แล้วคุณสมบัติบางอย่างยังเพิ่มการปรับแต่ง:
ยินดีต้อนรับการมีส่วนร่วมทุกประเภท