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

Text rendering issue #301

Closed
daver32 opened this issue Feb 22, 2022 · 2 comments
Closed

Text rendering issue #301

daver32 opened this issue Feb 22, 2022 · 2 comments

Comments

@daver32
Copy link

daver32 commented Feb 22, 2022

Hello, I'm trying to render some text but what happens is that only the first character ever used is rendered. So in my example here, the counter starts with 1, so it will only ever render the character "1" and leave a blank space in other's stead.

I've tried a couple different fonts, as well as platforms (Arch Linux and Windows), but the issue persists.

Crate versions:

piston_window = "0.121.0"
piston2d-graphics = "0.41.0"

Here's a minimal example:

use graphics::{Graphics, Text, Transformed};
use piston_window::{PistonWindow, WindowSettings};

fn main() {
    let mut window: PistonWindow = WindowSettings::new("Title", [256, 256])
        .exit_on_esc(true)
        .resizable(false)
        .build()
        .expect("Failed to build Piston window. ");

    let mut glyphs = window
        .load_font("LiberationSans-Regular.ttf")
        .expect("Failed to load the font. ");

    let mut counter = 1;

    while let Some(event) = window.next() {
        window.draw_2d(&event, |context, graphics, _device| {
            graphics.clear_color([1.0, 1.0, 1.0, 1.0]);

            let str = format!("{}", counter);

            Text::new_color([0.0, 0.0, 0.0, 1.0], 32)
                .draw(
                    &str,
                    &mut glyphs,
                    &context.draw_state,
                    context.trans(32.0, 32.0).transform,
                    graphics,
                )
                .unwrap();

            counter += 1;
        });
    }
}

Is there something I'm missing or could this be a bug?

@VictorKoenders
Copy link

Duplicate of #258 (comment) (also includes a workaround that works for me)

@daver32
Copy link
Author

daver32 commented Mar 22, 2022

Duplicate of #258 (comment) (also includes a workaround that works for me)

It works, thank you!

@daver32 daver32 closed this as completed Mar 22, 2022
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