diff --git a/src/graphics_gl.rs b/src/graphics_gl.rs index 0f27e7b223..29e8bd89ab 100644 --- a/src/graphics_gl.rs +++ b/src/graphics_gl.rs @@ -18,6 +18,8 @@ use glutin::ContextBuilder; use std::mem::size_of; use std::ptr::null; use glium::framebuffer::ColorAttachment::Texture; +use std::sync::Arc; +use sensor_control::CaptureProvider; //use shader::Shader; @@ -101,7 +103,7 @@ static TEXTURE_CHECKERBOARD : [GLfloat; 12] = [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, ]; -pub fn run() { +pub fn run(capture_provider: Arc) { let event_loop = EventLoop::new(); let window = WindowBuilder::new(); let gl_window = ContextBuilder::new() @@ -149,9 +151,10 @@ pub fn run() { gl::GenTextures(1, &mut tex); gl::BindTexture(gl::TEXTURE_2D, tex); - //let img = image::open(&Path::new("sneslogo.png")) - //let img = image::open(&Path::new("n64logo.png")) - let img = image::open(&Path::new("sample.png")) + //let filename = "sneslogo.png"; + let filename = "n64logo.png"; + //let filename = "sample.png"; + let img = image::open(&Path::new(filename)) .expect("failed to load") .to_rgba(); @@ -248,7 +251,7 @@ pub fn run() { } event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Wait; + //*control_flow = ControlFlow::Wait; match event { Event::LoopDestroyed => return, Event::WindowEvent { event, .. } => match event { @@ -284,6 +287,39 @@ pub fn run() { }, _ => (), } + + // TODO: This belongs in a worker thread with buffers on both producer and consumer. + if let Some(capture) = capture_provider.get_capture() { + if let Ok(image) = capture.get_depth_image() { + let width = image.get_width_pixels() as i32; + let height = image.get_height_pixels() as i32; + println!("Size: {}x{}", width, height); + let buffer = image.get_buffer(); + + //let img_ptr: *const c_void = raw_img.as_ptr() as *const c_void; + + + unsafe { + gl::BindTexture(gl::TEXTURE_2D, tex); + gl::TexImage2D( + gl::TEXTURE_2D, + 0, + gl::RGBA as i32, + //format as i32, + width, + height, + 0, + gl::RGBA, + //format, + gl::UNSIGNED_BYTE, + buffer as *const c_void, + ); + } + *control_flow = ControlFlow::Poll; + + gl_window.swap_buffers().unwrap(); + } + } }); } diff --git a/src/main.rs b/src/main.rs index f55c0ba8c6..34e5be39d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,11 +62,11 @@ pub mod old_k4a_wrapper; pub mod sensor_control; pub fn main() { - /*let capture_provider = Arc::new(CaptureProvider::new()); + let capture_provider = Arc::new(CaptureProvider::new()); let capture_provider2= capture_provider.clone(); - thread::spawn(move || capture_thread(capture_provider));*/ + thread::spawn(move || capture_thread(capture_provider)); //graphics_grr::run(capture_provider2).unwrap(); //graphics_glium::run_glium(); - graphics_gl::run(); + graphics_gl::run(capture_provider2); }