piston_window icon indicating copy to clipboard operation
piston_window copied to clipboard

Glyphs cache only properly caches texture for first character

Open kaikalii opened this issue 4 years ago • 5 comments

I have noticed an error that only seems to be present in newer versions of piston_window. This error is not present in version 0.89.0, the version I was on before updating.

I have tested this code on version 0.100.0:

use piston_window::*;

fn main() {
    let mut window: PistonWindow = WindowSettings::new("test", (400, 400)).build().unwrap();
    let mut glyphs = Glyphs::from_bytes(
        include_bytes!("roboto.ttf"),
        window.create_texture_context(),
        TextureSettings::new(),
    )
    .unwrap();
    while let Some(event) = window.next() {
        window.draw_2d(&event, |context, graphics, _| {
            clear([0.0, 0.0, 0.0, 1.0], graphics);
            text(
                [1.0; 4],
                30,
                "test text",
                &mut glyphs,
                context.transform.trans_pos([100.0; 2]),
                graphics,
            )
            .unwrap()
        });
    }
}

This opens a window that looks like this: image

As you can see, only the letter t was properly cached. When trying other strings, it is apparent that only the first character introduced to the glyphs cache is actually cached.

I have tested it with different fonts, and the same error occurs.

I looked at the GlyphsCache code, but I couldn't figure out why this would be happening. Am I doing something wrong, or is this a bug?

kaikalii avatar Jul 23 '19 21:07 kaikalii