Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: How to know FPSs?

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Lisbon, Portugal
    Posts
    17

    How to know FPSs?

    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!

  2. #2
    Guest

    Re: How to know FPSs?

    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..

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Lisbon, Portugal
    Posts
    17

    Re: How to know FPSs?

    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!

  4. #4
    Intern Newbie
    Join Date
    Nov 2003
    Location
    Gliwice, Slaskie, Poland
    Posts
    45

    Re: How to know FPSs?

    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();
       }
    }

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: How to know FPSs?

    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!
    What are you talking about!?

    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 ....

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Lisbon, Portugal
    Posts
    17

    Re: How to know FPSs?

    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!

  7. #7
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,651

    Re: How to know FPSs?

    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

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    628

    Re: How to know FPSs?

    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..
    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).

  9. #9
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Lisbon, Portugal
    Posts
    17

    Re: How to know FPSs?

    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!

  10. #10

    Re: How to know FPSs?

    I think:

    if ( 999 < (GetTickCount() - dwLastTime) )

    works a bit better. ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •