Fixed capture

This commit is contained in:
Thomas Forgione 2018-10-11 15:22:59 +02:00
parent c6c26f7201
commit 1e638681a4
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
2 changed files with 23 additions and 2 deletions

View File

@ -58,6 +58,8 @@ fn main() {
// Set verbose flag
verbose_log::set(matches.occurrences_of("verbose") > 0);
let mut capture_count = 0;
use std::f64::{MIN, MAX};
let mut bbox = BoundingBox3::new(
Vector3::new(MAX, MAX, MAX),
@ -177,7 +179,25 @@ fn main() {
camera.target.x(), camera.target.y(), camera.target.z());
println!("\tUp: ({}, {}, {})",
camera.up.x(), camera.up.y(), camera.up.z());
}
},
Event::WindowEvent {
event: WindowEvent::KeyboardInput {
input: glutin::KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::C),
state: ElementState::Pressed, ..
}, ..
}, ..
} => {
// Make a screenshot
let size = renderer.gl_window().get_inner_size().unwrap();
let cap = renderer.capture(size);
cap.save(format!("capture-{}.png", capture_count)).unwrap();
capture_count += 1;
},
_ => (),
}

View File

@ -223,7 +223,8 @@ impl Renderer {
/// Returns a RgbaImageData of the corresponding frame.
pub fn capture_rgba_image_data(&self, dimensions: LogicalSize) -> RgbaImageData {
let dimensions: (u32, u32) = dimensions.into();
let dpi = self.gl_window().get_hidpi_factor();
let dimensions: (u32, u32) = dimensions.to_physical(dpi).into();
let rect = Rect {
left: 0,