piston_window icon indicating copy to clipboard operation
piston_window copied to clipboard

Weird *1.5 scale on rendered images

Open m4ntis opened this issue 5 years ago • 3 comments

Hi there,

I'm using the latest version of piston_window (0.117.0) on linux (updated arch), and I'm having this weird issue where images I render using the code below are all *1.5 zoomed. I can get it to kinda work with something hacky along the lines of c.transform.zoom(0.667) but it's weird + the scaling isn't perfect and I get bad aliasing.

use piston_window::*;
use std::path::Path;

fn main() {
    let mut window: PistonWindow = WindowSettings::new("foo", (640, 480))
        .exit_on_esc(true)
        .build()
        .unwrap();

    let mut ctx = window.create_texture_context();
    let mask = Texture::from_path(
        &mut ctx,
        Path::new("assets/foo.png"),
        Flip::None,
        &TextureSettings::new(),
    )
    .unwrap();

    while let Some(e) = window.next() {
        match e {
            Event::Loop(Loop::Render(_)) => {
                window.draw_2d(&e, |c, g, d| {
                    clear(color::hex("4d4d4d"), g);
                    image(&mask, c.transform, g);
                    ctx.encoder.flush(d);
                });
            }
            _ => {}
        }
    }
}

m4ntis avatar Jan 18 '21 15:01 m4ntis

So I found a temporary fix that avoids the aliasing, c.transform.zoom(2.0 / 3.0) instead of c.transform.zoom(0.667). Still, weird solution I'd love to avoid + idk what runtime performance issues may arise from scaling each loaded asset

m4ntis avatar Jan 18 '21 17:01 m4ntis

This does not seem to happen with the Sdl2Window backend.

m4ntis avatar Jan 23 '21 15:01 m4ntis

Do you have a retina screen?

bvssvni avatar Jan 24 '21 02:01 bvssvni