How do I display Frames Per Second?
-
Tuesday, April 04, 2006 1:41 AMThe subject says it all; how do I see what FPS my app is getting? DirectX must be stashing that info somewhere!
All Replies
-
Tuesday, April 04, 2006 1:47 AM
Every example I've seen requires working it out by using a timer and counting how many times a second the screen gets refreshed.
But it's possible that it's sitting in there also, it's been a while since I did DX.
-
Tuesday, April 04, 2006 3:27 AM
Have a look at the following sample... Call the CalculateFrameRate each time you render to the device, and either display it to the device in code or change you forms title text to display it ie. thisform1.title.txt = CalculateFrameRate().ToString();
using System;
using System.Collections.Generic;
using System.Text;namespace VirtualRealm.Mdx.Common
{
public class Utility
{
#region Basic Frame Counterprivate static int lastTick;
private static int lastFrameRate;
private static int frameRate;public static int CalculateFrameRate()
{
if (System.Environment.TickCount - lastTick >= 1000)
{
lastFrameRate = frameRate;
frameRate = 0;
lastTick = System.Environment.TickCount;
}
frameRate++;
return lastFrameRate;
}
#endregion}
} -
Tuesday, April 04, 2006 3:57 AMDoes C# have an equivalent method to System.getNanoTime() in Java? That would make life alot easier...
-
Tuesday, April 04, 2006 4:40 AMEnvironment.TickCount is probably what you are looking for.
-
Tuesday, April 04, 2006 11:22 AMCool! Thanks for the code.

