#### Archived

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

# Calculating FPS

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

## Recommended Posts

I was wondering how i could calculate frames per second in a game i am making. I have a way to do it in VB, but i need one for C++. I was going to use the CTimer.GetSecond(), but to use that i have to include afx.h, and when i do that i get linking errors, so is there a different function i could use like VB''s Timer? Here is the one from a different game done in VB ''Calculate the frame rate dim i as integer, fps as integer, tLast as integer If i = 30 Then If tLast <> 0 Then fps = 30 / (Timer - tLast) tLast = Timer i = 0 End If i = i + 1 ''(then write out variable fps) t2sherm ô¿ô

##### Share on other sites
If you are still interested in how to calculate it in C++, please mail me at mitolah@hotmail.com and I''ll tell you how to do it...

I will not say it here... it takes too much code!!

Greetings Dark

##### Share on other sites

static DWORD dwLastTime = 0;
static float fFPS = 0;
static DWORD dwFrames = 0;

// Keep track of the time lapse and frame count
DWORD dwTime = timeGetTime();
dwFrames++;

// Update the frame rate once per second
DWORD dwTimeDiff = dwTime - dwLastTime;
if (dwTimeDiff > 1000) {
fFPS = (float)dwFrames / dwTimeDiff * 1000;
dwLastTime = dwTime;
dwFrames = 0;
}

// Print fFPS to show FPS
...

ArgoN

Thank You!

t2sherm ô¿ô

##### Share on other sites
There''s always the "count the frames, check the time and divide" trick.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632995
• Total Posts
3009774
• ### Who's Online (See full list)

There are no registered users currently online

×