mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-27 05:18:27 +00:00
Add accurate framerate to basic example
This commit is contained in:
parent
f70ddfa29e
commit
fc82d41154
@ -1,6 +1,8 @@
|
|||||||
//! A basic self-contained example to get you from zero-to-demo-window as fast
|
//! A basic self-contained example to get you from zero-to-demo-window as fast
|
||||||
//! as possible.
|
//! as possible.
|
||||||
|
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use glow::HasContext;
|
use glow::HasContext;
|
||||||
use glutin::{event_loop::EventLoop, WindowedContext};
|
use glutin::{event_loop::EventLoop, WindowedContext};
|
||||||
use imgui_winit_support::WinitPlatform;
|
use imgui_winit_support::WinitPlatform;
|
||||||
@ -23,10 +25,19 @@ fn main() {
|
|||||||
let mut ig_renderer = imgui_glow_renderer::auto_renderer(gl, &mut imgui_context)
|
let mut ig_renderer = imgui_glow_renderer::auto_renderer(gl, &mut imgui_context)
|
||||||
.expect("failed to create renderer");
|
.expect("failed to create renderer");
|
||||||
|
|
||||||
|
let mut last_frame = Instant::now();
|
||||||
|
|
||||||
// Standard winit event loop
|
// Standard winit event loop
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, _, control_flow| {
|
||||||
*control_flow = glutin::event_loop::ControlFlow::Wait;
|
*control_flow = glutin::event_loop::ControlFlow::Wait;
|
||||||
match event {
|
match event {
|
||||||
|
glutin::event::Event::NewEvents(_) => {
|
||||||
|
let now = Instant::now();
|
||||||
|
imgui_context
|
||||||
|
.io_mut()
|
||||||
|
.update_delta_time(now.duration_since(last_frame));
|
||||||
|
last_frame = now;
|
||||||
|
}
|
||||||
glutin::event::Event::MainEventsCleared => {
|
glutin::event::Event::MainEventsCleared => {
|
||||||
winit_platform
|
winit_platform
|
||||||
.prepare_frame(imgui_context.io_mut(), window.window())
|
.prepare_frame(imgui_context.io_mut(), window.window())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user