How to count frames?

I have got a “simple” question:

How can I get the current framerate of my OpenGL programm.

I count how often my drawing function is called in one second, but is this really the true framerate?

What´s with buffer swapping / flipping and such things? Is there a better way to count fps?

Diapolo

Your method is correct. But you can also count the framerate by messuring the time it takes to render a frame, this will not be updating only once per second. The most accurate way to do this is to use this functions:

__inline __int64 GetCycleNumber(){
//RDTSC instruction
__asm _emit 0x0F __asm _emit 0x31
}

int GetMHz(){
LARGE_INTEGER t1,t2,tf;
__int64 c1,c2;

QueryPerformanceFrequency(&tf);
QueryPerformanceCounter(&t1);
c1 = GetCycleNumber();
    //Just wait a little
    for (int t = 0; t < 5000000; t++);
QueryPerformanceCounter(&t2);
c2 = GetCycleNumber();

return (int) ((c2 - c1) * tf.QuadPart / (t2.QuadPart - t1.QuadPart) / 1000000);

}

Time = (ThisCycleNumber - LastCycleNumber) / (1000000 * MHz);