Skip to content

Commit

Permalink
Upgrade glium example to winit 0.29 and glium 0.34 (#86)
Browse files Browse the repository at this point in the history
* 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] <support@github.com>

* 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] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marijn Suijten <marijns95@gmail.com>
  • Loading branch information
dependabot[bot] and MarijnS95 authored Apr 9, 2024
1 parent c8ec2f0 commit ced9df0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 54 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
108 changes: 55 additions & 53 deletions examples/glium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
}

0 comments on commit ced9df0

Please sign in to comment.