Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glyphs cache only properly caches texture for first character #258

Open
kaikalii opened this issue Jul 23, 2019 · 5 comments
Open

Glyphs cache only properly caches texture for first character #258

kaikalii opened this issue Jul 23, 2019 · 5 comments

Comments

@kaikalii
Copy link

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?

@bvssvni
Copy link
Member

bvssvni commented Jul 23, 2019

Have you tried the "hello_world" example here? https://github.com/pistondevelopers/piston-examples

@bvssvni
Copy link
Member

bvssvni commented Jul 24, 2019

I got the same bug running your example.

@bvssvni
Copy link
Member

bvssvni commented Jul 24, 2019

It seems that the bug appears when loading a font from included bytes.

@kaikalii
Copy link
Author

I tried several things, and it seems that my code was missing the line at the end of the draw_2d closure:

glyphs.factory.encoder.flush(device);

I have never needed this before, so I assume that requiring this flushing has something to do with a recent change to the API. Was this done automatically before?

@bvssvni
Copy link
Member

bvssvni commented Jul 24, 2019

Ah! Yes, the flush is needed when using gfx_graphics. This is because of the caching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants