• Advertisement

Archived

This topic is now archived and is closed to further replies.

Calculating FPS

This topic is 5854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''d like to display the framerate as frames per seconds while my program is running. However, I can''t really figure out how to calculate the FPS. Is there some DirectX function that can do this for me? If anyone has suggestions or sample code, I''d appreciate it. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
easy problem, psuedo code:

StartTime=Timer;

Do GameLoop
{
DrawScene;
Fps++;
if (Timer-StartTime>1.0f)
{
DisplayFps Fps; //DrawText or whatever
Fps=0
StartTime=Timer;
}
}

Second way:
Do GameLoop
{
StartTime=Timer;
DrawScene;
DisplayFps 1.0f/(Timer-StartTime)
}

I don't do c/c++ much, you'll have to ask someone else what the
function to get the current time is.

Hope this helps,
-Michael

Edited by - thr33d on August 12, 2001 7:57:35 PM

Share this post


Link to post
Share on other sites
Use timeGetTime() to find the number of milliseconds since windows was started. Since it reports in milliseconds, swap the 1.0f''s in Michaels code for 1000.0f.

Share this post


Link to post
Share on other sites
The D3DXSprite wrapper downloadable from my site has the FPS code you need. Download it from:

  Downloads:  ZeroOne Realm

Share this post


Link to post
Share on other sites
G''day!

On my site ( http://www.drunkenhyena.com/docs/dhFPSTimer.phtml ) is the code for a timer class. It does what you need and you can easily plug it in to your code in a few minutes.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
FPS = 1.0f/(static_cast(DelayInMainLoopInMilliseconds)/1000.0f);

- err, the last signiture sucked bigtime!

Share this post


Link to post
Share on other sites

  • Advertisement