X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=main.rs;h=5507f4a7fc09b01340f33f223c754e05ba57c79c;hb=53d5a5f7c140229b88f0fd1bf6cc4325c5a32e73;hp=71495b41d09f310d0d051ae51e5bff0b78b4677f;hpb=e1501d87592aa1657d604f33814dc891047ab16c;p=mandelwow.git diff --git a/main.rs b/main.rs index 71495b4..5507f4a 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(); @@ -101,17 +110,6 @@ fn main() { KeyboardInput(Pressed, _, Some(VirtualKeyCode::B)) => { bounding_box_enabled ^= true; }, - KeyboardInput(Pressed, _, Some(VirtualKeyCode::F)) => { - fullscreen ^= true; - if fullscreen { - glutin::WindowBuilder::new() - .with_fullscreen(glutin::get_primary_monitor()) - .rebuild_glium(&display).unwrap(); - } else { - glutin::WindowBuilder::new() - .rebuild_glium(&display).unwrap(); - } - }, KeyboardInput(Pressed, _, Some(VirtualKeyCode::P)) => { pause ^= true; }, @@ -121,6 +119,22 @@ fn main() { KeyboardInput(Pressed, _, Some(VirtualKeyCode::PageDown)) => { t -= 0.01; }, + KeyboardInput(Pressed, _, Some(VirtualKeyCode::F10)) => { + screenshot(&display); + }, + KeyboardInput(Pressed, _, Some(VirtualKeyCode::F11)) => { + fullscreen ^= true; + if fullscreen { + // Not implemented on Linux + glutin::WindowBuilder::new() + .with_fullscreen(glutin::get_primary_monitor()) + .with_depth_buffer(24) + .rebuild_glium(&display).unwrap(); + } else { + //glutin::WindowBuilder::new() + // .rebuild_glium(&display).unwrap(); + } + }, ev => camera.process_input(&ev), } }