You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I'm a complete newbie in this question.
In a lot of tutorials and example codes, I see that render is being performed in Event::RedrawRequested event, but according to Winit documentation continuously drawn apps, such as games should use control_flow.set_poll() and render inside Event::MainEventsCleared. Can anybody provide any information on this matter?
Reference from the docs.
// ControlFlow::Poll continuously runs the event loop, even if the OS hasn't// dispatched any events. This is ideal for games and similar applications.
control_flow.set_poll();// ControlFlow::Wait pauses the event loop if no events are available to process.// This is ideal for non-game applications that only update in response to user// input, and uses significantly less power/CPU time than ControlFlow::Poll.
control_flow.set_wait();match event {Event::WindowEvent{event:WindowEvent::CloseRequested,
..
} => {println!("The close button was pressed; stopping");
control_flow.set_exit();},Event::MainEventsCleared => {// Application update code.// Queue a RedrawRequested event.//// You only need to call this if you've determined that you need to redraw, in// applications which do not always need to. Applications that redraw continuously// can just render here instead.
window.request_redraw();},Event::RedrawRequested(_) => {// Redraw the application.//// It's preferable for applications that do not render continuously to render in// this event rather than in MainEventsCleared, since rendering in here allows// the program to gracefully handle redraws requested by the OS.},
_ => ()
I think the Winit documentation is not very clear about it, this comment in the Rend3 project is quite enlightening: RedrawRequested/RedrawEventsCleared will only be fired if the window size is non-zero. As such you should always render in RedrawRequested and use MainEventsCleared for things that need to keep running when minimized.
Reacted by Mark Nefedov and Ben Hansen
Repository owner locked and limited conversation to collaborators on Dec 10, 2022
Activity
CatCode79 commentedon Nov 20, 2022
I think the Winit documentation is not very clear about it, this comment in the Rend3 project is quite enlightening:
RedrawRequested/RedrawEventsCleared will only be fired if the window size is non-zero. As such you should always render in RedrawRequested and use MainEventsCleared for things that need to keep running when minimized.