Changing the output resolution without changing the window size #14018
-
I'm trying to implement a video resolution option for my game and I'm stuck on changing the actual resolution. For tests I set up a new blank project (Cargo.toml is default + bevy 0.13.2 as a dependency): use bevy::core::FrameCount;
use bevy::prelude::*;
use bevy::window::{WindowMode, WindowResolution};
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
mode: WindowMode::BorderlessFullscreen,
visible: false,
..default()
}),
..default()
}))
.add_systems(Startup, setup)
.add_systems(Update, make_visible)
.run()
}
fn make_visible(mut window: Query<&mut Window>, frames: Res<FrameCount>) {
if frames.0 == 3 {
window.single_mut().visible = true;
}
}
fn setup(
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
let background_image: Handle<Image> = asset_server.load("textures/background.png");
commands
.spawn(Camera2dBundle::default());
commands
.spawn(SpriteBundle {
texture: background_image,
..Default::default()
});
} It simply renders a background image (1920x1080, matches my monitor size). There is a discussion #10738, but using suggested solution of resolution: WindowResolution::new(3840.0, 2160.0).with_scale_factor_override(2.0) does not seem to work properly. It just displays image twice as big. AFAIK what I need is to change the logical size of the window without changing the physical size (correct me if i'm wrong). But is there any way to do it? fn make_visible(mut window: Query<&mut Window>, frames: Res<FrameCount>) {
if frames.0 == 3 {
window.single_mut().visible = true;
// Workaround below!! vvv
let resolution = &mut window.single_mut().resolution;
resolution.set_physical_resolution(3840, 2160);
resolution.set_scale_factor_override(Some(2.0));
// Workaround abow!! ^^^
}
} does not change the output. Is there any proper way to implement it right now? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I think the correct way to achieve this is configuring camera (there could be more than one camera in scene, each of them could have different resolution multipliers (for example portrait of main hero could have lower/higher resolution than main scene)). You are using Camera2dBundle::default(), I propose to change Camera2dBundle::projection, namely set OrthographicProjection::scaling_mode to ScalingMode::WindowSize(0.5), for example description of OrthographicProjection already has example for decreasing resolution:
In your case you should increase resolution instead. |
Beta Was this translation helpful? Give feedback.
-
Code:
Produced output:
You can play with WindowSize and see, that camera's output area reacts on it changing/setting |
Beta Was this translation helpful? Give feedback.
-
is there a solution like this for Camera3d? |
Beta Was this translation helpful? Give feedback.
I think the correct way to achieve this is configuring camera (there could be more than one camera in scene, each of them could have different resolution multipliers (for example portrait of main hero could have lower/higher resolution than main scene)). You are using Camera2dBundle::default(), I propose to change Camera2dBundle::projection, namely set OrthographicProjection::scaling_mode to ScalingMode::WindowSize(0.5), for example description of OrthographicProjection already has example for decreasing resolution:
Configure the orthographic projection to one world unit per 100 window pixels: