Skip to content

Commit ced9df0

Browse files
Upgrade glium example to winit 0.29 and glium 0.34 (#86)
* build(deps): update glium requirement from 0.27.0 to 0.33.0 Updates the requirements on [glium](https://github.com/glium/glium) to permit the latest version. - [Release notes](https://github.com/glium/glium/releases) - [Changelog](https://github.com/glium/glium/blob/master/CHANGELOG.md) - [Commits](glium/glium@v0.27.0...v0.33.0) --- updated-dependencies: - dependency-name: glium dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]> * Make `glium` example compatible with latest `winit`-less `glutin` crate `glutin` detached itself from `winit` by using `raw-window-handle` for window interop, and a minimal `glutin-winit` crate for lightweight window creation and event handling where necessary. This also makes the `glutin` crate more generic to use, for non-windowing GL cases. * Upgrade `glium` example to `winit 0.29` and `glium 0.34` --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Marijn Suijten <[email protected]>
1 parent c8ec2f0 commit ced9df0

File tree

2 files changed

+57
-54
lines changed

2 files changed

+57
-54
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ v4l-sys = { path = "v4l-sys", version = "0.3.0", optional = true }
1515
v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit", optional = true }
1616

1717
[dev-dependencies]
18-
glium = "0.27.0"
18+
glium = "0.34"
1919
jpeg-decoder = "0.3.0"
20+
winit = "0.29"
2021

2122
[features]
2223
default = ["v4l2"]

examples/glium.rs

+55-53
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::thread;
44
use std::time::Instant;
55

66
use glium::index::PrimitiveType;
7-
use glium::{glutin, Surface};
7+
use glium::Surface;
88
use glium::{implement_vertex, program, uniform};
99

1010
use jpeg_decoder as jpeg;
@@ -54,10 +54,8 @@ fn main() -> io::Result<()> {
5454
println!("Active parameters:\n{}", params);
5555

5656
// Setup the GL display stuff
57-
let event_loop = glutin::event_loop::EventLoop::new();
58-
let wb = glutin::window::WindowBuilder::new();
59-
let cb = glutin::ContextBuilder::new().with_vsync(true);
60-
let display = glium::Display::new(wb, cb, &event_loop).unwrap();
57+
let event_loop = winit::event_loop::EventLoop::new().map_err(io::Error::other)?;
58+
let (_window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
6159

6260
// building the vertex buffer, which contains all the vertices that we will draw
6361
let vertex_buffer = {
@@ -148,53 +146,57 @@ fn main() -> io::Result<()> {
148146
}
149147
});
150148

151-
event_loop.run(move |event, _, control_flow| {
152-
let t0 = Instant::now();
153-
let data = rx.recv().unwrap();
154-
let t1 = Instant::now();
155-
156-
let image =
157-
glium::texture::RawImage2d::from_raw_rgb_reversed(&data, (format.width, format.height));
158-
let opengl_texture = glium::texture::Texture2d::new(&display, image).unwrap();
159-
160-
// building the uniforms
161-
let uniforms = uniform! {
162-
matrix: [
163-
[1.0, 0.0, 0.0, 0.0],
164-
[0.0, 1.0, 0.0, 0.0],
165-
[0.0, 0.0, 1.0, 0.0],
166-
[0.0, 0.0, 0.0, 1.0f32]
167-
],
168-
tex: &opengl_texture
169-
};
170-
171-
// drawing a frame
172-
let mut target = display.draw();
173-
target.clear_color(0.0, 0.0, 0.0, 0.0);
174-
target
175-
.draw(
176-
&vertex_buffer,
177-
&index_buffer,
178-
&program,
179-
&uniforms,
180-
&Default::default(),
181-
)
182-
.unwrap();
183-
target.finish().unwrap();
184-
185-
// polling and handling the events received by the window
186-
if let glutin::event::Event::WindowEvent {
187-
event: glutin::event::WindowEvent::CloseRequested,
188-
..
189-
} = event
190-
{
191-
*control_flow = glutin::event_loop::ControlFlow::Exit;
192-
}
149+
event_loop
150+
.run(move |event, elwt| {
151+
let t0 = Instant::now();
152+
let data = rx.recv().unwrap();
153+
let t1 = Instant::now();
154+
155+
let image = glium::texture::RawImage2d::from_raw_rgb_reversed(
156+
&data,
157+
(format.width, format.height),
158+
);
159+
let opengl_texture = glium::texture::Texture2d::new(&display, image).unwrap();
160+
161+
// building the uniforms
162+
let uniforms = uniform! {
163+
matrix: [
164+
[1.0, 0.0, 0.0, 0.0],
165+
[0.0, 1.0, 0.0, 0.0],
166+
[0.0, 0.0, 1.0, 0.0],
167+
[0.0, 0.0, 0.0, 1.0f32]
168+
],
169+
tex: &opengl_texture
170+
};
193171

194-
print!(
195-
"\rms: {}\t (buffer) + {}\t (UI)",
196-
t1.duration_since(t0).as_millis(),
197-
t0.elapsed().as_millis()
198-
);
199-
});
172+
// drawing a frame
173+
let mut target = display.draw();
174+
target.clear_color(0.0, 0.0, 0.0, 0.0);
175+
target
176+
.draw(
177+
&vertex_buffer,
178+
&index_buffer,
179+
&program,
180+
&uniforms,
181+
&Default::default(),
182+
)
183+
.unwrap();
184+
target.finish().unwrap();
185+
186+
// polling and handling the events received by the window
187+
if let winit::event::Event::WindowEvent {
188+
event: winit::event::WindowEvent::CloseRequested,
189+
..
190+
} = event
191+
{
192+
elwt.exit();
193+
}
194+
195+
print!(
196+
"\rms: {}\t (buffer) + {}\t (UI)",
197+
t1.duration_since(t0).as_millis(),
198+
t0.elapsed().as_millis()
199+
);
200+
})
201+
.map_err(io::Error::other)
200202
}

0 commit comments

Comments
 (0)