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

Problems with hidpi settings #237

Open
SrTobi opened this issue Nov 9, 2018 · 2 comments
Open

Problems with hidpi settings #237

SrTobi opened this issue Nov 9, 2018 · 2 comments

Comments

@SrTobi
Copy link

SrTobi commented Nov 9, 2018

I have basically the same problem that #226 describes.
On my monitor that has its dpi set to 85 the frame buffer is much smaller than the actual window size. On my monitor other monitor it works just fine.

window.window.window.get_hidpi_factor() also prints out the correct factor of 1.166666

image

Cargo.toml

[dependencies]
rand = "0.5"
piston_window = "0.81"
shader_version = "0.3"
image = "0.20.0"

main.rs

extern crate rand;
extern crate piston_window;
extern crate image as im;

use piston_window::*;

fn main() {
    let texture_count = 2024;
    let frames = 200;
    let size = 64.0;
    let mut window: PistonWindow = WindowSettings::new("piston", [1024; 2])
        .exit_on_esc(true)
        .resizable(true)
        .build()
        .unwrap();

    let textures = {
        (0..texture_count).map(|_| {
            let mut img = im::ImageBuffer::new(2, 2);
            for x in 0..2 {
                for y in 0..2 {
                    img.put_pixel(x, y,
                        im::Rgba([rand::random(), rand::random(), rand::random(), 255]));
                }
            }
            Texture::from_image(
                &mut window.factory,
                &img,
                &TextureSettings::new()
            ).unwrap()
        }).collect::<Vec<Texture<_>>>()
    };

    let mut positions = (0..texture_count)
        .map(|_| (rand::random(), rand::random()))
        .collect::<Vec<(f64, f64)>>();

    let mut counter = 0;
    window.set_bench_mode(true);
    while let Some(e) = window.next() {
        if let Some(_) = e.render_args() {
            counter += 1;

            if counter % 5 == 0 {
                let Size {width: w, height: h} = window.size();
                println!("Window Size {}, {}", w, h);

                let Size {width, height} = window.window.draw_size();
                println!("Draw Size {}, {}", width, height);

                println!("Scale: {}, {}", w as f64 / width as f64, h as f64 / height as f64);

                println!("dpi: {}", window.window.window.get_hidpi_factor());
            }
        }

        window.draw_2d(&e, |c, g| {
            clear([0.0, 0.0, 0.0, 1.0], g);
            for p in &mut positions {
                let (x, y) = *p;
                *p = (x + (rand::random::<f64>() - 0.5) * 0.01,
                      y + (rand::random::<f64>() - 0.5) * 0.01);
            }
            for i in 0..texture_count {
                let p = positions[i];
                image(&textures[i], c.transform
                    .trans(p.0 * 1024.0 * 3.5, p.1 * 1024.0 * 3.5).zoom(size), g);
            }
        });
    }
}
@SrTobi
Copy link
Author

SrTobi commented Nov 9, 2018

Ok, Just found out, that it works fine with the previous version 0.80:

rand = "0.5"
shader_version = "0.3"
piston_window = "0.80"
image = "0.19.0"

@nixpulvis
Copy link

I'm not sure if my issue in crazymykl/rust-life#2 is the same, but I'm trying to render to a X11 screen with 1920x1080 reported resolution. The code I was using that's build against the old version of piston works, but newer versions are scaling things. For example on master the window size is reported as:

let size = [1920u32, 1080u32];
let mut window: PistonWindow = WindowSettings::new("Life", size)...
println!("{:?}", window.size());
// => Size { width: 1152.0, height: 648.0 }

Something is wrong here, since I want to simply render pixel by pixel. I'm wondering if there's anything that needs to be done with respect to rust-windowing/winit#837?

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