How we calculate the Frame count?

see these ideology:
0 - we get the start time;
//on loop:
1 - we draw the things;
2 - we count the frames;
3 - we get the new time;
4 - if it's 1 second:
1 - we get the start time;
2 - we get\draw the frame count.
0:
1
2
3
4
LARGE_INTEGER timeStart;
LARGE_INTEGER timeEnd;
QueryPerformanceCounter(&timeStart);
int FrameCount=0;

1-now on loop the things...
2 :
FrameCount++;
3:
QueryPerformanceCounter(&timeEnd);
4:
1
2
3
4
5
6
7
LONGLONG numCounts =(timeEnd.QuadPart-timeStart.QuadPart);
if(numCounts>=1000000)
    {
        QueryPerformanceCounter(&timeStart);
        frMain.SetTitle("Frame count: " + NumberToString(FrameCount));
        FrameCount=0;
    }

but i belive that these calculation is wrong, because i used the MSIAfterburner program that give me 60fps instead my calculation: 30fps.
https://imgur.com/a/awFcT
what i'm doing wrong?


Moderator: why the code button continues with a bug\error? everytime that i create the topic i can't use code button or i will get an error?
https://imgur.com/a/ldvZF
Last edited on
Why don't you use a timer instead?
When you start it set count to 0, every time the timer fires int count and change the display.
because i'm using directx and maybe i need avoid windows messages for speed... i don't know. but now works fine:
timeStart=static_cast <float> (clock ()) / static_cast <float> (CLOCKS_PER_SEC);
on loop:
1
2
3
4
5
6
7
8
9
10
timeEnd=static_cast <float> (clock ()) / static_cast <float> (CLOCKS_PER_SEC);
    FrameCount++;
    float ActualTime = (static_cast <float> (clock ()) / static_cast <float> (CLOCKS_PER_SEC)) - timeStart;
     //frMain.SetTitle("Frame count: " + NumberToString(numCounts));
    if(ActualTime>=1)
    {
        timeStart=static_cast <float> (clock ()) / static_cast <float> (CLOCKS_PER_SEC);
        frMain.SetTitle("Frame count: " + NumberToString(FrameCount));
        FrameCount=0;
    }

and don't forget include the time header file:
#include <time.h>
thank you so much for all
Topic archived. No new replies allowed.