Skip to content

Commit

Permalink
Enable getting delta time in OnResize and OnMove
Browse files Browse the repository at this point in the history
  • Loading branch information
NogginBops committed Mar 18, 2023
1 parent 2856193 commit f2c430b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/OpenTK.Windowing.Desktop/GameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,24 @@ protected virtual void OnRenderFrame(FrameEventArgs args)
{
RenderFrame?.Invoke(args);
}

/// <summary>
/// The current time since the last update.
/// This function is useful when implementing updates on resize using windows.
/// </summary>
/// <returns>The time since the last update.</returns>
public double TimeSinceLastUpdate()
{
return (float)_watchUpdate.Elapsed.TotalSeconds;
}

/// <summary>
/// Resets the time since the last update.
/// This function is useful when implementing updates on resize using windows.
/// </summary>
public void ResetTimeSinceLastUpdate()
{
_watchUpdate.Restart();
}
}
}
18 changes: 17 additions & 1 deletion tests/LocalTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,37 @@ protected override void OnLoad()

}

float time = 0;

protected override void OnRenderFrame(FrameEventArgs args)
{
base.OnRenderFrame(args);

GL.ClearColor(Color4.Coral);
time += (float)args.Time;
if (time > 8) time = 0;

Color4 color = Color4.FromHsv(new Vector4(time / 8f, 1, 1, 1));

GL.ClearColor(color);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


SwapBuffers();
}

protected override void OnUpdateFrame(FrameEventArgs args)
{
base.OnUpdateFrame(args);
}

protected override void OnResize(ResizeEventArgs e)
{
base.OnResize(e);
}

protected override void OnMove(WindowPositionEventArgs e)
{
base.OnMove(e);
}
}
}

0 comments on commit f2c430b

Please sign in to comment.