Skip to content

Commit

Permalink
Updates glium dependency to 0.30
Browse files Browse the repository at this point in the history
This change updates to the latest version of glium (0.30), which brings
glutin to version 0.27 and winit to 0.25. This fixes known issue
[#1773](rust-windowing/winit#1773) in winit
0.19 on Linux X11.

The key stubstanitive change to the examples is the change from glutin's
`EventsLoop` to `EventLoop`. Instead of a user-defined while loop where
`EventsLoop::poll_events` is called, `EventLoop` has switched to a run
function which is event-driven by glutin's core. This slightly changes
the program structure.

The other changes are minor, as glutin moved a few data structures into
modules instead of having everything visible at the top-level.
  • Loading branch information
tgockel committed Aug 12, 2021
1 parent d687246 commit f0ea2cb
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -13,7 +13,7 @@ readme = "README.md"

[dependencies]
nalgebra = "0.18"
glium = "0.25"
glium = "0.30"
log = "0.4"
glsl = "3.0"
num-traits = "0.2"
Expand Down
43 changes: 27 additions & 16 deletions examples/cube.rs
@@ -1,7 +1,16 @@
use std::time::Instant;

use floating_duration::TimeAsFloat;
use glium::{glutin, Surface};
use glium::{
glutin::{
self,
dpi::PhysicalSize,
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
},
Surface,
};
use nalgebra as na;

use rendology::{
Expand Down Expand Up @@ -99,10 +108,10 @@ fn main() {
simple_logger::init_with_level(log::Level::Info).unwrap();

// Initialize glium
let mut events_loop = glutin::EventsLoop::new();
let events_loop = EventLoop::new();
let display = {
let window_builder = glutin::WindowBuilder::new()
.with_dimensions(WINDOW_SIZE.into())
let window_builder = WindowBuilder::new()
.with_inner_size(PhysicalSize::new(WINDOW_SIZE.0, WINDOW_SIZE.1))
.with_title("Rendology example: Cube");
let context_builder = glutin::ContextBuilder::new();
glium::Display::new(window_builder, context_builder, &events_loop).unwrap()
Expand All @@ -112,17 +121,19 @@ fn main() {
let mut pipeline = Pipeline::create(&display, &Default::default()).unwrap();

let start_time = Instant::now();
let mut quit = false;
while !quit {
events_loop.poll_events(|event| {
if let glutin::Event::WindowEvent {
event: glutin::WindowEvent::CloseRequested,
..
} = event
{
quit = true;
}
});
events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::LoopDestroyed => return,
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
return
},
_ => (),
},
_ => (),
}

let time = start_time.elapsed().as_fractional_secs() as f32;
let scene = scene(time);
Expand All @@ -135,7 +146,7 @@ fn main() {
.unwrap();

target.finish().unwrap();
}
});
}

fn scene(time: f32) -> Scene {
Expand Down
61 changes: 39 additions & 22 deletions examples/custom_scene_core.rs
Expand Up @@ -3,8 +3,24 @@ use std::time::Instant;
use floating_duration::TimeAsFloat;
use nalgebra as na;

use glium::glutin::{self, ElementState, VirtualKeyCode, WindowEvent};
use glium::Surface;
use glium::{
glutin::{
self,
dpi::PhysicalSize,
event::{
ElementState,
Event,
VirtualKeyCode,
WindowEvent,
},
event_loop::{
ControlFlow,
EventLoop,
},
window::WindowBuilder,
},
Surface,
};

use rendology::{
basic_obj, BasicObj, InstancingMode, Light, Mesh, RenderList, ShadedScenePass,
Expand Down Expand Up @@ -232,10 +248,10 @@ fn main() {
simple_logger::init_with_level(log::Level::Info).unwrap();

// Initialize glium
let mut events_loop = glutin::EventsLoop::new();
let events_loop = EventLoop::new();
let display = {
let window_builder = glutin::WindowBuilder::new()
.with_dimensions(WINDOW_SIZE.into())
let window_builder = WindowBuilder::new()
.with_inner_size(PhysicalSize::new(WINDOW_SIZE.0, WINDOW_SIZE.1))
.with_title("Rendology example: Cube");
let context_builder = glutin::ContextBuilder::new();
glium::Display::new(window_builder, context_builder, &events_loop).unwrap()
Expand All @@ -253,18 +269,19 @@ fn main() {
let mut pipeline = Pipeline::create(&display, &pipeline_config).unwrap();

let start_time = Instant::now();
let mut quit = false;
while !quit {
events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;

let mut recreate_pipeline = false;
events_loop.poll_events(|event| {
if let glutin::Event::WindowEvent { event, .. } = event {
match event {
WindowEvent::CloseRequested => {
quit = true;
}
WindowEvent::KeyboardInput { input, .. }
if input.state == ElementState::Pressed =>
{
match event {
Event::LoopDestroyed => return,
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
return
},
WindowEvent::KeyboardInput { input, .. } =>
if input.state == ElementState::Pressed {
// Allow toggling effects
match input.virtual_keycode {
Some(VirtualKeyCode::F1) => {
Expand All @@ -290,11 +307,11 @@ fn main() {
}
_ => (),
}
}
_ => (),
}
}
});
},
_ => (),
},
_ => (),
};

if recreate_pipeline {
pipeline = Pipeline::create(&display, &pipeline_config).unwrap();
Expand All @@ -311,7 +328,7 @@ fn main() {
.unwrap();

target.finish().unwrap();
}
});
}

fn scene(time: f32) -> Scene {
Expand Down
43 changes: 27 additions & 16 deletions examples/lines.rs
@@ -1,7 +1,16 @@
use std::time::Instant;

use floating_duration::TimeAsFloat;
use glium::{glutin, Surface};
use glium::{
glutin::{
self,
dpi::PhysicalSize,
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
},
Surface
};
use nalgebra as na;

use rendology::{
Expand Down Expand Up @@ -116,10 +125,10 @@ fn main() {
simple_logger::init_with_level(log::Level::Info).unwrap();

// Initialize glium
let mut events_loop = glutin::EventsLoop::new();
let events_loop = EventLoop::new();
let display = {
let window_builder = glutin::WindowBuilder::new()
.with_dimensions(WINDOW_SIZE.into())
let window_builder = WindowBuilder::new()
.with_inner_size(PhysicalSize::new(WINDOW_SIZE.0, WINDOW_SIZE.1))
.with_title("Rendology example: Cube");
let context_builder = glutin::ContextBuilder::new();
glium::Display::new(window_builder, context_builder, &events_loop).unwrap()
Expand All @@ -129,17 +138,19 @@ fn main() {
let mut pipeline = Pipeline::create(&display, &Default::default()).unwrap();

let start_time = Instant::now();
let mut quit = false;
while !quit {
events_loop.poll_events(|event| {
if let glutin::Event::WindowEvent {
event: glutin::WindowEvent::CloseRequested,
..
} = event
{
quit = true;
}
});
events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::LoopDestroyed => return,
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
return
},
_ => (),
},
_ => (),
}

let time = start_time.elapsed().as_fractional_secs() as f32;
let scene = scene(time);
Expand All @@ -152,7 +163,7 @@ fn main() {
.unwrap();

target.finish().unwrap();
}
});
}

fn scene(time: f32) -> Scene {
Expand Down
69 changes: 41 additions & 28 deletions examples/particles.rs
Expand Up @@ -4,7 +4,21 @@ use std::time::Instant;

use coarse_prof::profile;
use floating_duration::TimeAsFloat;
use glium::{glutin, Surface};
use glium::{
glutin::{
self,
dpi::PhysicalSize,
event::{
Event,
ElementState,
VirtualKeyCode,
WindowEvent
},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
},
Surface,
};
use nalgebra as na;

use rendology::particle::Particle;
Expand Down Expand Up @@ -146,10 +160,10 @@ fn main() {
simple_logger::init_with_level(log::Level::Info).unwrap();

// Initialize glium
let mut events_loop = glutin::EventsLoop::new();
let events_loop = EventLoop::new();
let display = {
let window_builder = glutin::WindowBuilder::new()
.with_dimensions(WINDOW_SIZE.into())
let window_builder = WindowBuilder::new()
.with_inner_size(PhysicalSize::new(WINDOW_SIZE.0, WINDOW_SIZE.1))
.with_title("Rendology example: Cube");
let context_builder = glutin::ContextBuilder::new();
glium::Display::new(window_builder, context_builder, &events_loop).unwrap()
Expand All @@ -160,30 +174,29 @@ fn main() {

let start_time = Instant::now();
let mut last_time = Instant::now();
let mut quit = false;
while !quit {
events_loop.run(move |event, _, control_flow| {
profile!("frame");

events_loop.poll_events(|event| {
if let glutin::Event::WindowEvent {
event: glutin::WindowEvent::CloseRequested,
..
} = event
{
quit = true;
} else if let glutin::Event::WindowEvent {
event: glutin::WindowEvent::KeyboardInput { input, .. },
..
} = event
{
if input.state == glutin::ElementState::Pressed
&& input.virtual_keycode == Some(glutin::VirtualKeyCode::P)
{
coarse_prof::write(&mut std::io::stdout()).unwrap();
coarse_prof::reset();
}
}
});
*control_flow = ControlFlow::Poll;

match event {
Event::LoopDestroyed => return,
Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
return
},
WindowEvent::KeyboardInput { input, .. } => {
if input.state == ElementState::Pressed
&& input.virtual_keycode == Some(VirtualKeyCode::P)
{
coarse_prof::write(&mut std::io::stdout()).unwrap();
coarse_prof::reset();
}
},
_ => (),
},
_ => (),
}

let time = start_time.elapsed().as_fractional_secs() as f32;
let dt = last_time.elapsed().as_fractional_secs() as f32;
Expand All @@ -199,7 +212,7 @@ fn main() {
.unwrap();

target.finish().unwrap();
}
});
}

fn scene(time: f32, dt: f32) -> Scene {
Expand Down

0 comments on commit f0ea2cb

Please sign in to comment.