Skip to content
Browse files

[Examples] Calculate timing information in GameWindowStates

  • Loading branch information...
1 parent d49dacb commit c5dcc8a93b64419208a0a824b06f151266e3124f @thefiddler thefiddler committed Jan 7, 2014
Showing with 16 additions and 4 deletions.
  1. +16 −4 Source/Examples/OpenTK/Test/GameWindowStates.cs
View
20 Source/Examples/OpenTK/Test/GameWindowStates.cs
@@ -25,6 +25,8 @@ public class GameWindowStates : GameWindow
int texture;
bool mouse_in_window = false;
bool viewport_changed = true;
+ Stopwatch watch = new Stopwatch();
+ double update_time, render_time;
public GameWindowStates()
: base(800, 600, GraphicsMode.Default)
@@ -204,6 +206,9 @@ static int DrawLegacyJoysticks(Graphics gfx, IList<JoystickDevice> joysticks, in
protected override void OnUpdateFrame(FrameEventArgs e)
{
+ double clock_time = watch.Elapsed.TotalSeconds;
+ update_time += e.Time;
+
using (Graphics gfx = Graphics.FromImage(TextBitmap))
{
int line = 0;
@@ -226,7 +231,14 @@ protected override void OnUpdateFrame(FrameEventArgs e)
DrawString(gfx, String.Format("Mouse (absolute): {0}", new Vector3(Mouse.X, Mouse.Y, Mouse.WheelPrecise)), line++);
DrawString(gfx, String.Format("Bounds: {0}", Bounds), line++);
DrawString(gfx, String.Format("ClientRectangle: {0}", ClientRectangle), line++);
- DrawString(gfx, TypedText.ToString(), line++);
+ DrawString(gfx, String.Format("Vsync: {0}", VSync), line++);
+ DrawString(gfx, String.Format("Frequency: Update ({0:f1}/{1:f1}); Render ({2:f1}/{3:f1})",
+ UpdateFrequency, TargetUpdateFrequency, RenderFrequency, TargetRenderFrequency), line++);
+ DrawString(gfx, String.Format("Period: Update ({0:f1}/{1:f1}); Render ({2:f1}/{3:f1})",
+ UpdatePeriod, TargetUpdatePeriod, RenderPeriod, TargetRenderPeriod), line++);
+ DrawString(gfx, String.Format("Time drift: Clock {0:f4}; Update {1:f4}; Render {2:f4}",
+ clock_time, clock_time - update_time, clock_time - render_time), line++);
+ DrawString(gfx, String.Format("Text: {0}", TypedText.ToString()), line++);
line = DrawKeyboards(gfx, line);
line = DrawMice(gfx, line);
@@ -268,8 +280,8 @@ int DrawJoysticks(Graphics gfx, int line)
protected override void OnLoad(EventArgs e)
{
- base.OnLoad(e);
-
+ watch.Start();
+
GL.ClearColor(Color.MidnightBlue);
GL.Enable(EnableCap.Texture2D);
@@ -292,7 +304,7 @@ protected override void OnResize(EventArgs e)
protected override void OnRenderFrame(FrameEventArgs e)
{
- base.OnRenderFrame(e);
+ render_time += e.Time;
System.Drawing.Imaging.BitmapData data = TextBitmap.LockBits(
new System.Drawing.Rectangle(0, 0, TextBitmap.Width, TextBitmap.Height),

0 comments on commit c5dcc8a

Please sign in to comment.
Something went wrong with that request. Please try again.