Bug in multihead X11/Xorg viewport and camera positioning. Unable to display viewport in top left corner of window. Camera translation requires unnatural offsets to take effect. Also, spurious scale factor.
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
I've been testing bevy with some plugins and I can't figure how the camera translation and scaling works.
On a 1080p screen I have to translate the default 2d camera position on the x axis by precisely `1920/6+40` pixels to arrive at the actual origin.. That is `1920/(31/30)`.. I think I'm misunderstanding something fundamental here or something else is going on that I can't figure out.
I've tried to set the window scaling factor to 1.0 with the override as per documentation https://bevyengine.org/examples/Window/scale-factor-override/ but that doesn't seem to make any difference.
```rust
primary_window: Some(Window {
title: "I am a window!".into(),
resolution: WindowResolution::new(1920.0, 1080.0)
.with_scale_factor_override(1.0),
decorations: false,
mode: WindowMode::Windowed,
present_mode: PresentMode::AutoVsync,
// Tells wasm to resize the window according to the available canvas
fit_canvas_to_parent: true,
// Tells wasm not to override default event handling, like F5, Ctrl+R etc.
prevent_default_event_handling: false,
window_theme: Some(WindowTheme::Dark),
..default()
```
I've also tested that I'm not going fully mad by setting the viewport position and origin on one of the cameras and that doesn't actually land in the higher left corner.. The cameras also don't seem to have any render target attached so I couldn't query what it thinks it is.
```rust
fn setup(mut commands: Commands, asset_server: Res) {
let mut camera2d = Camera2dBundle::default();
// println!("{:?}", camera.transform);
// println!("{:?}", camera.global_transform);
// bevy::log::debug!("{:?}", camera.transform);
// bevy::log::debug!("{:?}", camera.global_transform);
let mut camera3d = Camera3dBundle::default();
// camera2d.projection.scale = 0.5;
//camera2d.transform.translation.x += 1920.0 / 6.0 + 40.0;
//camera2d.transform.translation.y += 1080.0 / 4.0; // += 720.0; // / 4.0;
// camera2d.camera.physical_target_size();
camera2d.camera.order = 1;
camera2d.transform.look_at(Vec3::ZERO, Vec3::Y);
camera2d.camera.viewport = Some(Viewport {
physical_position: UVec2 { x: 0, y: 0 },
physical_size: UVec2 { x: 1920, y: 1080 },
..default()
});
bevy::log::info!("{:?}", camera2d.camera.logical_target_size());
bevy::log::info!("{:?}", camera2d.camera.physical_target_size());
bevy::log::info!("{:?}", camera3d.camera.logical_target_size());
bevy::log::info!("{:?}", camera3d.camera.physical_target_size());
commands.spawn(camera2d);
commands.spawn(camera3d);
commands.spawn(LdtkWorldBundle {
ldtk_handle: asset_server.load("ldtk/Therac2D.ldtk"),
..default()
});
}
```
This is where it thinks 0,0 is and 1920x1080 size means:

My latest suspicion is that maybe the multihead configuration on my computer is somehow messing with bevy's calculations.
I have the following config:
```
❯ xrandr [22:53:43]
Screen 0: minimum 320 x 200, current 3360 x 2560, maximum 16384 x 16384
eDP-1 connected primary 1920x1080+0+1480 (normal left inverted right x axis y axis) 382mm x 215mm
1920x1080 300.01*+ 60.00 + 59.97 59.96 59.93
DP-1-0 connected 1440x2560+1920+0 right (normal left inverted right x axis y axis) 597mm x 336mm
2560x1440 59.95*+
```
Is bevy doing pixel calculations based on the entire X screen perhaps ?
Game log output:
```
2023-12-10T21:56:41.573335Z INFO bevy_winit::system: Creating new window "I am a window!" (0v0)
2023-12-10T21:56:41.575852Z INFO log: Guessed window scale factor: 1.3333333333333333
2023-12-10T21:56:41.731947Z INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 3080 Laptop GPU", vendor: 4318, device: 9372, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "545.29.02", backend: Vulkan }
2023-12-10T21:56:41.822852Z INFO log: Gamepad /dev/input/event9 (Sony Interactive Entertainment Wireless Controller) connected.
2023-12-10T21:56:41.859993Z INFO GAME_RIIR: None
2023-12-10T21:56:41.860011Z INFO GAME_RIIR: None
2023-12-10T21:56:41.860014Z INFO GAME_RIIR: None
2023-12-10T21:56:41.860017Z INFO GAME_RIIR: None
2023-12-10T21:56:41.860665Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux rolling Arch Linux", kernel: "6.5.9-arch1-1-g14", cpu: "AMD Ryzen 9 5900HX with Radeon Graphics", core_count: "8", memory: "30.8 GiB" }
2023-12-10T21:56:41.862336Z INFO bevy_input::gamepad: Gamepad { id: 0 } Connected
2023-12-10T21:56:46.027452Z INFO bevy_window::system: No windows are open, exiting
2023-12-10T21:56:46.028485Z INFO bevy_winit::system: Closing window 0v0
Compilation finished at Sun Dec 10 22:56:46
```
My cargo manifest has these versions set:
```toml
[dependencies]
bevy = "0.12"
bevy_ecs_ldtk = { version = "0.8", git = "https://github.com/trouv/bevy_ecs_ldtk", branch = "feat/bevy-0.12" }
space_editor = { git = "https://github.com/rewin123/space_editor.git", tag="v0.2.3" }
bevy_adventure = "0.6.0"
bevy_hanabi = "0.8"
[patch.crates-io]
bevy_ecs_tilemap = { git = "https://github.com/divark/bevy_ecs_tilemap", branch = "0.12-fixes" }
```
Contributor guide
Assessment
This issue has not been assessed yet.