texture was actually easy, it's just not redrawing without input

This commit is contained in:
Brandon Thomas committed 2020-04-13 04:44:45 -04:00
1 parent 5bd3f95bfa
commit ebb4bcaf3d
2 files changed
+44 -8

No files matched your search

+41 -5
View File
@@ -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<CaptureProvider>) {
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();
}
}
});
}
+3 -3
View File
@@ -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);
}