From: Bernie Innocenti Date: Sat, 8 Apr 2017 22:49:26 +0000 (-0400) Subject: Add screenshot function (F10). X-Git-Tag: v0.5.0~3 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8f2447cf29e1042d18121d93f59eb5b355ff48c1;p=mandelwow.git Add screenshot function (F10). --- diff --git a/Cargo.toml b/Cargo.toml index a858c2f..5c122ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ panic = 'abort' glium = "*" glutin = "*" genmesh = "0.4.1" +image = "0.12.0" obj = { version = "0.5", features = ["usegenmesh"] } libxm = "1.0.0" sdl2 = "*" diff --git a/main.rs b/main.rs index 71495b4..d7e8c00 100644 --- a/main.rs +++ b/main.rs @@ -4,6 +4,7 @@ extern crate glium; extern crate glutin; +extern crate image; extern crate libxm; extern crate sdl2; @@ -19,6 +20,14 @@ mod mandelwow; mod sound; mod support; +fn screenshot(display : &glium::Display) { + let image: glium::texture::RawImage2d = display.read_front_buffer(); + let image = image::ImageBuffer::from_raw(image.width, image.height, image.data.into_owned()).unwrap(); + let image = image::DynamicImage::ImageRgba8(image).flipv(); + let mut output = std::fs::File::create(&std::path::Path::new("screenshot.png")).unwrap(); + image.save(&mut output, image::ImageFormat::PNG).unwrap(); +} + fn main() { let _soundplayer = sound::start(); @@ -121,6 +130,9 @@ fn main() { KeyboardInput(Pressed, _, Some(VirtualKeyCode::PageDown)) => { t -= 0.01; }, + KeyboardInput(Pressed, _, Some(VirtualKeyCode::F10)) => { + screenshot(&display); + }, ev => camera.process_input(&ev), } }