I am trying to make a game loop using glium in rust. My goal is to get the screen to redraw 60 times per second. With the current event loop code I have, the frame only gets redrawn when the window size changes. I read in the glutin docs, that I need to call request_redraw somewhere, but I'm not sure how/where. This is my code so far:
event_loop.run(move |event, _target, control_flow| match event {
Event::LoopDestroyed => return,
Event::WindowEvent {
window_id: _window_id,
event: winevent,
} => match winevent {
WindowEvent::Resized(physical_size) => display.gl_window().resize(physical_size),
WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
}
_ => {}
},
Event::RedrawRequested(_window_id) => {
let mut target = display.draw();
target.clear_color_srgb(rng.gen(), rng.gen(), rng.gen(), 1.0);
target.finish().unwrap();
}
_ => {}
});
I haven't used
glium
before (I've been making some graphics applications directly off ofVulkano
for a while). However, perusing the API, it seems you can get your Window handle fromwinit
by going through a series of apis. I outlined them in the below code. Something like the below should work for you. The key is getting access to theWindow
handle fromwinit
. Scrolling through theWindow
API you should see this: request_redraw. You can then insert game-loop logic around your event handler like this: