• Announcements

Archived

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

Calculating FPS

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 on other sites
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 thefunction to get the current time is.Hope this helps,-MichaelEdited by - thr33d on August 12, 2001 7:57:35 PM



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 on other sites
The D3DXSprite wrapper downloadable from my site has the FPS code you need. Download it from:

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 on other sites
FPS = 1.0f/(static_cast(DelayInMainLoopInMilliseconds)/1000.0f);

- err, the last signiture sucked bigtime!

• Forum Statistics

• Total Topics
627714
• Total Posts
2978773

• 9
• 21
• 14
• 12
• 42