From: Bernie Innocenti Date: Sun, 29 Mar 2020 13:11:14 +0000 (+0900) Subject: Move screenshotting code to its own module X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=9ae471dda58c74e83c7080f7ea527105e063aef3;p=mandelwow.git Move screenshotting code to its own module --- diff --git a/lib.rs b/lib.rs index 24ef697..296f5b9 100644 --- a/lib.rs +++ b/lib.rs @@ -2,6 +2,7 @@ pub mod bounding_box; pub mod cube; pub mod mandelwow; pub mod shaded_cube; +pub mod screenshot; pub mod sound; pub mod support; pub mod text; @@ -12,17 +13,3 @@ pub use crate::cube::Cube; pub use crate::shaded_cube::ShadedCube; pub use crate::text::Text; pub use crate::timer::Timer; - -#[cfg(feature = "image")] -pub fn screenshot(display : &glium::Display) { - let image: glium::texture::RawImage2d<'_, u8> = display.read_front_buffer().unwrap(); - let image = image::ImageBuffer::from_raw(image.width, image.height, image.data.into_owned()).unwrap(); - let image = image::DynamicImage::ImageRgba8(image).flipv().to_rgb(); - let image = image::DynamicImage::ImageRgb8(image); - let mut output = std::fs::File::create(&std::path::Path::new("screenshot.png")).unwrap(); - image.write_to(&mut output, image::ImageFormat::PNG).unwrap(); -} - -#[cfg(not(feature = "image"))] -pub fn screenshot(_ : &glium::Display) { -} diff --git a/main.rs b/main.rs index 2bdcae8..86421b4 100644 --- a/main.rs +++ b/main.rs @@ -72,6 +72,7 @@ impl World { println!("xstep={} ystep={:?}", sea_xstep, sea_zstep); let mut sea = [[Vector3::zero(); SEA_ZSIZE]; SEA_XSIZE]; + #[allow(clippy::needless_range_loop)] for x in 0..SEA_XSIZE { for z in 0..SEA_ZSIZE { sea[x][z] = Vector3 { @@ -85,11 +86,11 @@ impl World { World { mandelwow_program, mandelwow_bbox: BoundingBox::new( - display, &mandelwow_bounds, bounding_box_program.clone()), + display, &mandelwow_bounds, bounding_box_program), mandelwow_bounds, bounding_box_enabled: true, - shaded_cube: ShadedCube::new(display, shaded_program.clone()), + shaded_cube: ShadedCube::new(display, shaded_program), text: text::Text::new(display), sea, @@ -310,7 +311,7 @@ fn main() { VirtualKeyCode::P => timer.pause ^= true, VirtualKeyCode::PageUp => timer.t += 0.1, VirtualKeyCode::PageDown => timer.t -= 0.2, - VirtualKeyCode::F10 => screenshot(&display), + VirtualKeyCode::F10 => screenshot::take_screenshot(&display), VirtualKeyCode::F11 | VirtualKeyCode::Return => { fullscreen ^= true; let fs = if fullscreen { diff --git a/screenshot.rs b/screenshot.rs new file mode 100644 index 0000000..19f2b13 --- /dev/null +++ b/screenshot.rs @@ -0,0 +1,13 @@ +#[cfg(feature = "image")] +pub fn take_screenshot(display : &glium::Display) { + let image: glium::texture::RawImage2d<'_, u8> = display.read_front_buffer().unwrap(); + let image = image::ImageBuffer::from_raw(image.width, image.height, image.data.into_owned()).unwrap(); + let image = image::DynamicImage::ImageRgba8(image).flipv().to_rgb(); + let image = image::DynamicImage::ImageRgb8(image); + let mut output = std::fs::File::create(&std::path::Path::new("screenshot.png")).unwrap(); + image.write_to(&mut output, image::ImageFormat::PNG).unwrap(); +} + +#[cfg(not(feature = "image"))] +pub fn take_screenshot(_ : &glium::Display) { +}