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

Scale issue with decimal scale factors on X11 #313

Open
Nazariglez opened this issue Feb 20, 2024 · 0 comments
Open

Scale issue with decimal scale factors on X11 #313

Nazariglez opened this issue Feb 20, 2024 · 0 comments

Comments

@Nazariglez
Copy link
Owner

Code to reproduce:

use notan::{draw::*, prelude::*};

fn main() -> Result<(), String> {
    notan::init_with(setup)
        .add_config(DrawConfig)
        .add_config(WindowConfig {
            width: 512,
            height: 512,
            ..Default::default()
        })
        .draw(draw)
        .build()
}

#[derive(AppState)]
struct State {
    screen: (Box<[u8]>, Texture),
}

fn setup(gfx: &mut Graphics) -> State {
    let (width, height) = gfx.size();
    let (width_u, height_u) = (width as usize, height as usize);

    let mut pixel_buf = vec![0; 4 * width_u * height_u].into_boxed_slice();

    // fill the pixel data with the color 0x424242
    for chunk in pixel_buf.chunks_exact_mut(4) {
        let [r, g, b, a] = chunk else { unreachable!() };
        *r = 42;
        *g = 42;
        *b = 42;
        *a = 255;
    }

    // place a pixel in each corner of the pixel data
    for (px, py) in [
        (0, 0),
        (width_u - 1, 0),
        (0, height_u - 1),
        (width_u - 1, height_u - 1),
    ] {
        for off in 0..4 {
            pixel_buf[px * 4 + py * (width_u * 4) + off] = 255;
        }
    }

    let tex = gfx
        .create_texture()
        .from_bytes(&pixel_buf, width, height)
        .build()
        .unwrap();

    State {
        screen: (pixel_buf, tex),
    }
}

fn draw(gfx: &mut Graphics, state: &mut State) {
    let mut draw = gfx.create_draw();
    draw.image(&state.screen.1);
    gfx.render(&draw);
}

Run with WINIT_X11_SCALE_FACTOR=1.0 cargo run.
Related info: https://docs.rs/winit/latest/winit/dpi/index.html#how-is-the-scale-factor-calculated

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

1 participant