add depth screenshot. I have an idea

main
_ 2022-01-09 16:19:31 +00:00
parent 176ff3de42
commit 8b799e817e
2 changed files with 17 additions and 0 deletions

View File

@ -300,6 +300,8 @@ async fn main () -> Result <()> {
let mut next_upf_print = 60; let mut next_upf_print = 60;
let mut last_upf_instant = Instant::now (); let mut last_upf_instant = Instant::now ();
let mut depth_buffer = vec! [0u32; 320 * 2 * 240 * 2];
'running: loop { 'running: loop {
let _frames_to_do = time_step.step (); let _frames_to_do = time_step.step ();
let mut player_gamepad = virtual_gamepad::VirtualGamepad::default (); let mut player_gamepad = virtual_gamepad::VirtualGamepad::default ();
@ -313,6 +315,16 @@ async fn main () -> Result <()> {
Event::KeyDown { keycode: Some (Keycode::R), .. } => { Event::KeyDown { keycode: Some (Keycode::R), .. } => {
game_state.logic.reset_level (&level); game_state.logic.reset_level (&level);
}, },
Event::KeyDown { keycode: Some (Keycode::F12), .. } => {
let depth_bytes: Vec <u8> = depth_buffer.iter ()
.map (|x| (x >> 16) as u16)
.map (|x| x.to_le_bytes ())
.flatten ()
.collect ();
let mut f = std::fs::File::create ("screenshot.data")?;
f.write_all (&depth_bytes)?;
},
Event::KeyDown { scancode: Some (Scancode::Space), repeat: false, .. } => { Event::KeyDown { scancode: Some (Scancode::Space), repeat: false, .. } => {
player_gamepad.jump.pressed = true; player_gamepad.jump.pressed = true;
}, },
@ -385,6 +397,10 @@ async fn main () -> Result <()> {
window.gl_swap_window (); window.gl_swap_window ();
unsafe {
gl::ReadPixels (0, 0, 320 * 2, 240 * 2, gl::DEPTH_COMPONENT, gl::UNSIGNED_INT, &mut depth_buffer [0] as *mut u32 as *mut std::ffi::c_void);
}
tokio::time::sleep (Duration::from_millis (10)).await; tokio::time::sleep (Duration::from_millis (10)).await;
} }

View File

@ -4,6 +4,7 @@ pub use std::{
CString, CString,
c_void, c_void,
}, },
io::Write,
time::Duration, time::Duration,
}; };