Fix surface texture size in some of the examples (#102)

This commit is contained in:
Jay Oster 2020-07-19 04:38:17 -07:00 committed by GitHub
parent 1191379388
commit fcc8f9fe65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 10 deletions

View file

@ -40,11 +40,11 @@ fn main() -> Result<(), Error> {
.build(&event_loop) .build(&event_loop)
.unwrap() .unwrap()
}; };
let mut hidpi_factor = window.scale_factor();
let mut pixels = { let mut pixels = {
let window_size = window.inner_size();
let surface = Surface::create(&window); let surface = Surface::create(&window);
let surface_texture = SurfaceTexture::new(WIDTH, HEIGHT, surface); let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, surface);
Pixels::new(WIDTH, HEIGHT, surface_texture)? Pixels::new(WIDTH, HEIGHT, surface_texture)?
}; };
let mut world = World::new(); let mut world = World::new();
@ -82,14 +82,8 @@ fn main() -> Result<(), Error> {
return; return;
} }
// Adjust high DPI factor
if let Some(factor) = input.scale_factor_changed() {
hidpi_factor = factor;
}
// Resize the window // Resize the window
if let Some(size) = input.window_resized() { if let Some(size) = input.window_resized() {
let size = size.to_logical(hidpi_factor);
pixels.resize(size.width, size.height); pixels.resize(size.width, size.height);
} }

View file

@ -10,7 +10,7 @@ optimize = ["log/release_max_level_warn"]
default = ["optimize"] default = ["optimize"]
[dependencies] [dependencies]
beryllium = { version = "0.2.1", features = ["extern_crate_raw_window_handle"] } beryllium = { version = "0.3.1", features = ["extern_crate_raw_window_handle"] }
env_logger = "0.7.1" env_logger = "0.7.1"
log = "0.4.8" log = "0.4.8"
pixels = { path = "../.." } pixels = { path = "../.." }

View file

@ -25,6 +25,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut pixels = { let mut pixels = {
let surface = Surface::create(&window); let surface = Surface::create(&window);
// TODO: Beryllium does not expose the SDL2 `GetDrawableSize` APIs, so choosing the correct
// surface texture size is not possible.
let surface_texture = SurfaceTexture::new(WIDTH, HEIGHT, surface); let surface_texture = SurfaceTexture::new(WIDTH, HEIGHT, surface);
Pixels::new(WIDTH, HEIGHT, surface_texture)? Pixels::new(WIDTH, HEIGHT, surface_texture)?
}; };

View file

@ -36,8 +36,9 @@ fn main() -> Result<(), Error> {
}; };
let mut pixels = { let mut pixels = {
let window_size = window.inner_size();
let surface = Surface::create(&window); let surface = Surface::create(&window);
let surface_texture = SurfaceTexture::new(WIDTH, HEIGHT, surface); let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, surface);
Pixels::new(WIDTH, HEIGHT, surface_texture)? Pixels::new(WIDTH, HEIGHT, surface_texture)?
}; };
let mut world = World::new(); let mut world = World::new();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 760 KiB

After

Width:  |  Height:  |  Size: 879 KiB