Advertisement

Frames Per Second

Started by August 10, 2000 01:31 AM
5 comments, last by zeotron 24 years, 3 months ago
I was wondering how I can measure frames per second. I have some code to get time and I was wondering how I can use it to measure FPS. Note: GetTickCount ( ); returns number of milliseconds since computer was started Here is the code: // Initializes Tick1, Tick2, and DTick Tick1 = GetTickCount ( ); Tick2 = GetTickCount ( ); DTick = (float)((Tick2 - Tick1) / 30.0); In the main loop of my program I have: // Update time Tick1 = Tick2; Tick2 = GetTickCount ( ); DTick = (float)((Tick2 - Tick1) / 30.0); Any help would be greatly appreciated. Zack Edited by - zeotron on 8/10/00 1:31:53 AM Edited by - zeotron on 8/10/00 1:32:35 AM
A moment enjoyed is not wasted. -Gamers.com
FPS=(float)1000.0f/(float)(Tick2-Tick1)
Advertisement
This is what you do: Save the Tick count before the update and after. Then take their difference and devide it into 1000.

For EX:

TicksAtBeginning = GetTickCount();// update the game and draw the new frame...TicksAtEnd = GetTickCount();FPS = 1000 / (TicksAtEnd - TicksAtBeginning); 


This code will give you the actuall FPS currentaly and not the average FPS that saving the frame count and total time elapsed would give you.

------------------------------

"My sword is like a menacing cloud, but instead of rain, blood will pour in its path." - Sehabeddin, Turkish Military Commander 1438.
------------------------------"My sword is like a menacing cloud, but instead of rain, blood will pour in its path." - Sehabeddin, Turkish Military Commander 1438.
I thought that was how to do it, but I just wanted to makre sure.

Thanks,
Zack
A moment enjoyed is not wasted. -Gamers.com
Whats the advantage/difference (if any) of using GetTickCount over timeGetTime() ??

- Keith (new to OpenGL programming)
Of course you would want to use a bit shift instead of division Dont want the FPS counter to hurt performance now do we?
Advertisement
Read the boards and this is what I came up with.

queryperformancecounter (if spelled right)
- Fastest and most accurate
TimeGetTime
- Second fastest and accurate
GetTickCount
- not so fast and not so accurate but it works without including the winmm library.

- Keith

This topic is closed to new replies.

Advertisement