rust piston write text
/* Node:
* This is using the piston_window version: 0.120.0
*/
extern crate piston_window;
use piston_window::*;
fn main() {
let font = include_bytes!("Assets\\arial.ttf");
let mut window: PistonWindow = WindowSettings::new("Text exxample", (640, 480))
.build()
.unwrap();
let mut glyphs = Glyphs::from_bytes(
font,
window.create_texture_context(),
TextureSettings::new(),
)
.unwrap();
while let Some(e) = window.next() {
window.draw_2d(&e, |context, graphics, device| {
clear([0.2; 4], graphics);
Text::new(12).draw(
"Text",
&mut glyphs,
&context.draw_state,
graphics
).unwrap();
glyphs.factory.encoder.flush(device);
}
}
}