When I tried to print text using the piston_window library, I found that the "10" was printed and only the "1" was displayed.Here is the code.
use piston_window::types::Color;
use piston_window::{text, Context, G2d, Glyphs, Transformed};
pub const TEXT_COLOR: Color = [1.0, 1.0, 1.0, 1.0];
pub fn main() {
let assets = find_folder::Search::ParentsThenKids(3, 3)
.for_folder("assets")
.unwrap();
let ref font = assets.join("retro-gaming.ttf");
let factory = window.factory.clone();
let mut glyphs = Glyphs::new(
font,
TextureContext {
factory,
encoder: window.factory.create_command_buffer().into(),
},
TextureSettings::new(),
)
.unwrap();
let mut window: PistonWindow = WindowSettings::new("test", [30, 30])
.resizable(false)
.exit_on_esc(true)
.build()
.unwrap_or_else(|e| panic!("Failed to build Window: {}", e));
while let Some(event) = window.next() {
window.draw_2d(&event, |ctx, g, _| {
text::Text::new_color(TEXT_COLOR, 20)
.draw(
"10",
&mut glyphs,
&ctx.draw_state,
ctx.transform.trans(0.0, 20.0),
g,
)
.unwrap();
});
}
}
I can't figure out what's wrong.I hope someone who knows can help me.Thanks.