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 11

Thread: how to calculate fps-stuff

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000
    Location
    ...
    Posts
    28

    how to calculate fps-stuff

    hi there,
    i'm sorry but i am not a experienced programmer....
    all i wanted to ask is : how can i measure the frames drawn in a second in my program?
    i played a few weeks with opengl and windows,but now i see,when i draw many triangles and polygons and many other stuff,my application is very very slow...so i want to see a difference how much slower my program is...please let me know how you guys do this stuff...

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Posts
    569

    Re: how to calculate fps-stuff

    you have to use 2 api calls :

    when you initialize your program,

    you call

    QueryPerformanceCounter(LARGE_INTEGER *frequency).

    LARGE_INTEGER is defined in windows.h and is a 64bits integer.

    This will give the frequency of your computer counter in ticks/seconds

    Now, before you start to draw you call

    QueryPerformanceCounter(LARGE_INTEGER* count).

    This will give you the count at wich the processor is.

    Just before you flush everything to drawing, you call QueryPerformanceCounter again and you'll have time it took to draw the scene in seconds like this :

    frametime = (count2 / frequency) - (count1 / frequency)

    the fps is 1/frametime.

    you write the time to your screen, and there you go!

    You can make a nice class "counter" to hide those ugly calls and LARGE_INTEGER.

    in the constructor you just call the query the frequency. Don't keep frequency it is not usefull, keep 1/frequency(and mutilply by your count value when you want to know the time, division are so slow compared to multiplication, but you should know that !)

  3. #3
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Breda, Netherlands
    Posts
    58

    Re: how to calculate fps-stuff

    Or, when you want to create something that's os independant:

    #include <time.h>
    time_t start, end;
    long frames = 0;


    before your start to draw stuff:

    start = time(NULL);

    when your app stops:

    end = time(NULL);

    and each frame your increment frames:

    frames++;

    fps is:

    fps = (float)frames/(float)(end-start);


    ain't that hard at all

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Posts
    569

    Re: how to calculate fps-stuff

    Just to say the performance counter is the most precise counter on a machine.

  5. #5
    Junior Member Newbie
    Join Date
    May 2005
    Location
    Germany
    Posts
    7

    Re: how to calculate fps-stuff

    I used this class for counting my fps:

    class fps_counter
    {
    private:
    LARGE_INTEGER *frequenz, *count_start, *count_ende;
    public:
    fps_counter()
    {
    QueryPerformanceCounter(frequenz);
    *frequenz = 1 / (*frequenz);
    }

    void get_start_frequency()
    {
    QueryPerformanceCounter(count_start);
    }

    void get_end_frequency()
    {
    QueryPerformanceCounter(count_ende);
    }

    LARGE_INTEGER get_frametime()
    {
    return ((*count_ende) * (*frequenz))-((*count_start) * (*frequenz));
    }
    } frametime;

    But my compiler says:

    error C2677: binary '/' : no global operator defined which takes type 'union _LARGE_INTEGER' (or there is no acceptable conversion)

    error C2676: binary '/' : 'union _LARGE_INTEGER' does not define this operator or a conversion to a type acceptable to the predefined operator

    How can I calculate my frametime now?

  6. #6
    Advanced Member Frequent Contributor Ehsan Kamrani's Avatar
    Join Date
    May 2005
    Posts
    537

    Re: how to calculate fps-stuff

    hi there,
    i'm sorry but i am not a experienced programmer....
    all i wanted to ask is : how can i measure the frames drawn in a second in my program?
    i played a few weeks with opengl and windows,but now i see,when i draw many triangles and polygons and many other stuff,my application is very very slow...so i want to see a difference how much slower my program is...please let me know how you guys do this stuff...
    An easy way is to use from the Fraps software. You can download it here: http://www.fraps.com/download.php
    Run this program and then run your executable file.You can see the frame rate in the top-left of your window.
    -Ehsan-

  7. #7
    Junior Member Newbie
    Join Date
    May 2005
    Location
    Germany
    Posts
    7

    Re: how to calculate fps-stuff

    Originally posted by Ehsan Kamrani:

    Run this program and then run your executable file.You can see the frame rate in the top-left of your window.
    -Ehsan-
    Nice software,thanks, but it does not solve my prob. Is there a way to convert LARGE_INTEGER to a usable format?!

  8. #8
    Junior Member Regular Contributor
    Join Date
    Jun 2004
    Location
    mexico
    Posts
    125

    Re: how to calculate fps-stuff

    long int ??

  9. #9
    Junior Member Newbie
    Join Date
    May 2005
    Location
    Germany
    Posts
    7

    Re: how to calculate fps-stuff

    Originally posted by zukko:
    long int ??
    error C2440: '=' : cannot convert from 'union _LARGE_INTEGER *' to 'long *'

    It seems as if LARGE_INTEGER is not convertable to
    any type I know and my compiler (MS VC++) cant multiply LARGE_INTEGERs.


  10. #10
    Junior Member Regular Contributor
    Join Date
    Feb 2004
    Posts
    248

    Re: how to calculate fps-stuff

    This should work:

    class fps_counter
    {
    private:
    LARGE_INTEGER frequenz, count_start, count_ende;
    public:
    fps_counter()
    {
    QueryPerformanceCounter(&frequenz);
    }

    void get_start_frequency()
    {
    QueryPerformanceCounter(&count_start);
    }

    void get_end_frequency()
    {
    QueryPerformanceCounter(&count_ende);
    }

    LARGE_INTEGER get_frametime()
    {
    return ((count_ende.QuadPart-count_start.QuadPart)/frequenz);
    }
    } frametime;

    get_frametime() will return milliseconds since frequenz is based on ticks per millisecond.

Posting Permissions

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