diff --git a/Cargo.toml b/Cargo.toml index 9832faf..3ebcec3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,9 @@ v4l-sys = { path = "v4l-sys", version = "0.3.0", optional = true } v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit", optional = true } [dev-dependencies] -glium = "0.27.0" +glium = "0.34" jpeg-decoder = "0.3.0" +winit = "0.29" [features] default = ["v4l2"] diff --git a/examples/glium.rs b/examples/glium.rs index 381e82e..c14f6a3 100644 --- a/examples/glium.rs +++ b/examples/glium.rs @@ -4,7 +4,7 @@ use std::thread; use std::time::Instant; use glium::index::PrimitiveType; -use glium::{glutin, Surface}; +use glium::Surface; use glium::{implement_vertex, program, uniform}; use jpeg_decoder as jpeg; @@ -54,10 +54,8 @@ fn main() -> io::Result<()> { println!("Active parameters:\n{}", params); // Setup the GL display stuff - let event_loop = glutin::event_loop::EventLoop::new(); - let wb = glutin::window::WindowBuilder::new(); - let cb = glutin::ContextBuilder::new().with_vsync(true); - let display = glium::Display::new(wb, cb, &event_loop).unwrap(); + let event_loop = winit::event_loop::EventLoop::new().map_err(io::Error::other)?; + let (_window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop); // building the vertex buffer, which contains all the vertices that we will draw let vertex_buffer = { @@ -148,53 +146,57 @@ fn main() -> io::Result<()> { } }); - event_loop.run(move |event, _, control_flow| { - let t0 = Instant::now(); - let data = rx.recv().unwrap(); - let t1 = Instant::now(); - - let image = - glium::texture::RawImage2d::from_raw_rgb_reversed(&data, (format.width, format.height)); - let opengl_texture = glium::texture::Texture2d::new(&display, image).unwrap(); - - // building the uniforms - let uniforms = uniform! { - matrix: [ - [1.0, 0.0, 0.0, 0.0], - [0.0, 1.0, 0.0, 0.0], - [0.0, 0.0, 1.0, 0.0], - [0.0, 0.0, 0.0, 1.0f32] - ], - tex: &opengl_texture - }; - - // drawing a frame - let mut target = display.draw(); - target.clear_color(0.0, 0.0, 0.0, 0.0); - target - .draw( - &vertex_buffer, - &index_buffer, - &program, - &uniforms, - &Default::default(), - ) - .unwrap(); - target.finish().unwrap(); - - // polling and handling the events received by the window - if let glutin::event::Event::WindowEvent { - event: glutin::event::WindowEvent::CloseRequested, - .. - } = event - { - *control_flow = glutin::event_loop::ControlFlow::Exit; - } + event_loop + .run(move |event, elwt| { + let t0 = Instant::now(); + let data = rx.recv().unwrap(); + let t1 = Instant::now(); + + let image = glium::texture::RawImage2d::from_raw_rgb_reversed( + &data, + (format.width, format.height), + ); + let opengl_texture = glium::texture::Texture2d::new(&display, image).unwrap(); + + // building the uniforms + let uniforms = uniform! { + matrix: [ + [1.0, 0.0, 0.0, 0.0], + [0.0, 1.0, 0.0, 0.0], + [0.0, 0.0, 1.0, 0.0], + [0.0, 0.0, 0.0, 1.0f32] + ], + tex: &opengl_texture + }; - print!( - "\rms: {}\t (buffer) + {}\t (UI)", - t1.duration_since(t0).as_millis(), - t0.elapsed().as_millis() - ); - }); + // drawing a frame + let mut target = display.draw(); + target.clear_color(0.0, 0.0, 0.0, 0.0); + target + .draw( + &vertex_buffer, + &index_buffer, + &program, + &uniforms, + &Default::default(), + ) + .unwrap(); + target.finish().unwrap(); + + // polling and handling the events received by the window + if let winit::event::Event::WindowEvent { + event: winit::event::WindowEvent::CloseRequested, + .. + } = event + { + elwt.exit(); + } + + print!( + "\rms: {}\t (buffer) + {}\t (UI)", + t1.duration_since(t0).as_millis(), + t0.elapsed().as_millis() + ); + }) + .map_err(io::Error::other) }