Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade glium example to winit 0.29 and glium 0.34 #86

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}