Hi all,
What's the best way to know the frames per second of my opengl application?
Best regards,
Paulo Matos
Hi all,
What's the best way to know the frames per second of my opengl application?
Best regards,
Paulo Matos
Paulo J. Matos : pocm@mega.ist.utl.pt
Instituto Superior Tecnico - Lisbon
Computer and Software Eng. - A.I.
- > http://mega.ist.utl.pt/~pocm
---
-> God had a deadline...
So, he wrote it all in Lisp!
just create a counter variable and add 1 to it every time you display a frame. Then every 1 of couple of seconds, divide by the number of seconds that have passed. It probably best to just do it every second..
Originally posted by r_shadrach:
just create a counter variable and add 1 to it every time you display a frame. Then every 1 of couple of seconds, divide by the number of seconds that have passed. It probably best to just do it every second..
Do you mean to put a counter in the end of each display callback?
But if I'm always dividing for each frame I'll have a division per frame which will just bring programs efficiency down!
Best regards,
Paulo Matos
Paulo J. Matos : pocm@mega.ist.utl.pt
Instituto Superior Tecnico - Lisbon
Computer and Software Eng. - A.I.
- > http://mega.ist.utl.pt/~pocm
---
-> God had a deadline...
So, he wrote it all in Lisp!
You can do it like this:
Code :void RenderScene() { static UINT uiFramesCounts = 0; static DWORD dwLastTime = 0; // Render here all the stuff you want // Add 1 to indicate that next frame was shown uiFrameCounts++; // Check if 1 second passed if ( dwLastTime-GetTickCount() >= 1000 ) { // uiFrameCounts now shows FPS value // which you can show on screen or whatever // Reset frames counter uiFrameCounts = 0; // Store time last FPS show was done dwLastTime = GetTickCounts(); } }
What are you talking about!?Originally posted by pmatos:
But if I'm always dividing for each frame I'll have a division per frame which will just bring programs efficiency down!
Worst case FDIV is 24 cycles on an Athlon.
Worst case expected target machine is 500 MHz.
That's twenty goddamn million float divisions per second and you're talking about losing efficiency because of doing it once per frame? Grrr ....
Can I put this piece of code in the registered idle function (if using glut)?
Is idle function called once per frame? (if not, then I cannot put the code there since I need a function that's called once per frame, right?)
Best regards,
Paulo Matos
Originally posted by enmaniac:
You can do it like this:
Code :void RenderScene() { static UINT uiFramesCounts = 0; static DWORD dwLastTime = 0; // Render here all the stuff you want // Add 1 to indicate that next frame was shown uiFrameCounts++; // Check if 1 second passed if ( dwLastTime-GetTickCount() >= 1000 ) { // uiFrameCounts now shows FPS value // which you can show on screen or whatever // Reset frames counter uiFrameCounts = 0; // Store time last FPS show was done dwLastTime = GetTickCounts(); } }
Paulo J. Matos : pocm@mega.ist.utl.pt
Instituto Superior Tecnico - Lisbon
Computer and Software Eng. - A.I.
- > http://mega.ist.utl.pt/~pocm
---
-> God had a deadline...
So, he wrote it all in Lisp!
The idle function is called when there is "some time to spare", don't use it.
Of course you have something that is called "once per frame", you must render something wright ? put the code in there.
Mikael
I don't do that because it's not uncommon to have the driver at work behind the scenes in the first few seconds of rendering. This is like an average ratio. I compute istant ratio between frames (I don't even require the division for who's interested to performance to this degree, I can do it with a mul and if you are smart with even less - i am not)...Originally posted by r_shadrach:
just create a counter variable and add 1 to it every time you display a frame. Then every 1 of couple of seconds, divide by the number of seconds that have passed. It probably best to just do it every second..
The advantage of this is a more responsive FPS counter. So, if you get 999fps for a long time then pop in some heavyweight geometry which takes you down to 9fps, you immediatly see the difference. Using average fps would put the counter on 998 and this would look bad.
Having a per-frame period also have other useful advantages (I am sure most games are using this approach).
I think this is the approach taken by the above code (modulo some typos...).
Originally posted by Obli:
I don't do that because it's not uncommon to have the driver at work behind the scenes in the first few seconds of rendering. This is like an average ratio. I compute istant ratio between frames (I don't even require the division for who's interested to performance to this degree, I can do it with a mul and if you are smart with even less - i am not)...
The advantage of this is a more responsive FPS counter. So, if you get 999fps for a long time then pop in some heavyweight geometry which takes you down to 9fps, you immediatly see the difference. Using average fps would put the counter on 998 and this would look bad.
Having a per-frame period also have other useful advantages (I am sure most games are using this approach).
Paulo J. Matos : pocm@mega.ist.utl.pt
Instituto Superior Tecnico - Lisbon
Computer and Software Eng. - A.I.
- > http://mega.ist.utl.pt/~pocm
---
-> God had a deadline...
So, he wrote it all in Lisp!
I think:
if ( 999 < (GetTickCount() - dwLastTime) )
works a bit better. ;-)