Calculating FPS
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!
easy problem, psuedo code:
StartTime=Timer;
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
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.
The D3DXSprite wrapper downloadable from my site has the FPS code you need. Download it from:
Downloads: ZeroOne Realm
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
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
FPS = 1.0f/(static_cast(DelayInMainLoopInMilliseconds)/1000.0f);
- err, the last signiture sucked bigtime!
- err, the last signiture sucked bigtime!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement