#Is there any way to get the Window Scaling?

8 messages · Page 1 of 1 (latest)

sage cape
#

Im trying to render pixel art along with Text that either corresponds to the scaling. Is there any way to get the Window Scaling at rendering?

austere oracle
sage cape
#

Should you story it as a resource?

austere oracle
#

If you want to change it from the default use the below code when adding Bevy's DefaultPlugins (note it is auto detected, so usually it's already what you want)

use bevy::prelude::*;
fn main() {
    let mut resolution = bevy::window::WindowResolution::new(1920,1080);
        // Set this to be the dpi scale you want. 1.0 effectively disables display scaling making logical pixels 1 to 1 with your monitor's physical pixels.
        .with_scale_factor_override(1.0);
    let mut app = App::new();
    app.add_plugins(DefaultPlugins.build().set(WindowPlugin{
            primary_window: Some(Window{
                resolution,
                ..default()
            }),
            ..default()
        })
    app.run();
}
#

To get the value at runtime:

fn my_system(primary_window_query: Query<&Window, With<PrimaryWindow>){
    let Ok(window) = primary_window_query.get_single() else {
        // if for some reason we don't have a primary window, do nothing
        return;
    }

    let scale_factor: f64 = window.scale_factor();
    // do what you want with the scale factor
}
sage cape
#

Is there a way to retrieve the dpi scaling value used but he os?

hoary siren
#

if you don't override it, the OS scaling value will be used

hoary siren