PistonDevelopers/graphics

Scaling issue when resizing window on macOS

emmabritton opened this issue · 5 comments

Description
When any piston program is run and the window is resized the graphics appear incorrectly.

To Reproduce
Run this:

extern crate piston;
extern crate graphics;
extern crate glutin_window;
extern crate opengl_graphics;

use piston::window::WindowSettings;
use piston::event_loop::*;
use piston::input::*;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::{ GlGraphics, OpenGL };

pub struct App {
    gl: GlGraphics,
}

impl App {
    fn render(&mut self, args: &RenderArgs) {
        use graphics::*;

        const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
        const RED:   [f32; 4] = [1.0, 0.0, 0.0, 1.0];

        let square = rectangle::square(0.0, 0.0, 50.0);
        let (x, y) = (args.width / 2., args.height / 2.);

        self.gl.draw(args.viewport(), |c, gl| {
            clear(GREEN, gl);

            let transform = c.transform.trans(x, y);
            rectangle(RED, square, transform, gl);
        });
    }

    fn update(&mut self, args: &UpdateArgs) {}
}

fn main() {
    let opengl = OpenGL::V3_2;

    let mut window: Window = WindowSettings::new(
        "spinning-square",
        [200, 200]
    )
        .opengl(opengl)
        .exit_on_esc(true)
        .build()
        .unwrap();

    let mut app = App {
        gl: GlGraphics::new(opengl)
    };

    let mut events = Events::new(EventSettings::new());
    while let Some(e) = events.next(&mut window) {
        if let Some(r) = e.render_args() {
            app.render(&r);
        }

        if let Some(u) = e.update_args() {
            app.update(&u);
        }
    }
}

and then resize the window

Expected behavior
The boxes should continue to appear in the centre of the window

Screenshots
Initial window:
Screenshot 2019-06-02 at 13 06 07

When I change the size (the square moves towards the top right as the windows grows):
Screenshot 2019-06-02 at 13 06 15

Hardware and Software

Piston versions:

piston = "0.43.0"
piston2d-graphics = "0.32.0"
pistoncore-glutin_window = "0.55.0"
piston2d-opengl_graphics = "0.62.0"

OS: macOS Mojave 10.14.4, 13.3-inch (2560 x 1600) - DPI is 2
Graphics card: Intel Iris Plus Graphics 640

Replicated the bug with Glutin backend. Works with SDL2 backend.

Same issue here. This is problematic because the Glutin backend is the one suggested in the getting-started section.

Same issue on Linux.

Can confirm that this happens to me on Linux with Wayland

I believe that this is a problem on both MacOS and Linux with Wayland, according to this comment in the glutin documentation.

The page suggests to explicitly resize the window on every Resized window event. I guess this is a glutin_window thing.