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 12

Thread: Finding FPS

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2000
    Location
    New Orleans, La, USA
    Posts
    14

    Finding FPS

    How would I find the FPS of my program. Not the average, but just so I can display it on the screen while my program is running.

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2000
    Posts
    18

    Re: Finding FPS

    To get the current FPS rate, you need to have some function called exactly once every second (I dunno how in win32 nor in X). Have it do something like:
    FPS_Rate = FPS_Counter;
    FPS_Counter = 0;

    Then every frame, increment FPS_Counter. FPS_Rate will contain the current FPS.

  3. #3
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Finding FPS

    Here's two useful functions for this:

    __inline __int64 GetCycleNumber(){
    __asm {
    RDTSC
    }
    }

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

    QueryPerformanceFrequency(&tf);
    QueryPerformanceCounter(&t1);
    c1 = GetCycleNumber();
    _asm {
    MOV EBX, 5000000
    WaitAlittle:
    DEC EBX
    JNZ WaitAlittle
    }
    QueryPerformanceCounter(&t2);
    c2 = GetCycleNumber();

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

    Call GetMHz in the beginning of your app and save the value. Then do like this:

    void Init(){
    MHz = GetMHz();
    }


    void render(){
    static LARGE_INTEGER last,current;
    double FPS;

    last = current;
    render_your_scene();
    current = GetCycleNumber();

    FPS = ((double) (current - last)) / (1000000.0 * MHz);

    }

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2000
    Posts
    1

    Re: Finding FPS

    Does ANSI C not have a timer function that will allow me to know when one second is up?

    if(timer()==1)
    {
    display FPS
    reset FPS counter
    reset timer
    }

  5. #5
    Guest

    Re: Finding FPS

    if ur making the program in windows, use settimer when your window is created. this will generate a WM_TIMER event every x amount of time (you set this to 1 second, of course). and when a WM_TIMER even occurs, simply save your framecount and reset the framecount to zero again.

  6. #6
    Intern Contributor
    Join Date
    Jul 2000
    Posts
    57

    Re: Finding FPS

    You might also just take the average of say 10 frames.

    start=time(NULL);
    .
    .
    fpscounter++;
    if(fpscounter >10)
    {
    fpscounter = 0;
    end=time(NULL);
    fps = 10 / (end - start);
    start=time(NULL);
    }

    (untested, offcouz )

    Anyway, that should work

    --> Divide Overflow

    [This message has been edited by Divide Overflow (edited 09-02-2000).]

  7. #7
    Guest

    Re: Finding FPS

    well, on Windows you could try


    render_function()
    {
    static long millisecs;
    static int frames;
    long t;

    frames++;
    if ((t =timeGetTime())-millisecs >= 1000) {
    /* show the frames here */
    ....
    frames = 0;
    millisecs = t;
    }

    /* for a Linux/UNIX application try gettimeofday() */

  8. #8
    Junior Member Regular Contributor
    Join Date
    Mar 2000
    Location
    Aurora, Illinois, USA
    Posts
    217

    Re: Finding FPS

    or try this technique..

    //pseudo code

    gettime(a);
    drawstuff();
    gettime(b);
    timediff=b-a; //in ms
    fps=1000/timediff

    THAT'S IT... Q.E.D.
    Navreet Gill [img]/forum/images/%%GRAEMLIN_URL%%/smile.gif[/img]

  9. #9
    Junior Member Newbie
    Join Date
    Sep 2000
    Posts
    25

    Re: Finding FPS

    What header file and/or libraries does the function timeGetTime() need?

    When I use timeGetTime I get this error:
    error LNK2001: unresolved external symbol __imp__timeGetTime@0

    Thanks,
    wolfman8k

    [This message has been edited by wolfman8k (edited 09-07-2000).]

  10. #10
    Junior Member Newbie
    Join Date
    Jun 2000
    Location
    NY
    Posts
    22

    Re: Finding FPS

    Hi wolfman8k!
    The easiest technic (in my opinion) for windows is the Message from HUMUS.
    you only have to use two Statements and three variables:

    LARGE_INTEGER before, after, ClockPerSec;
    QueryPerformanceFrequency(&ClockPerSec);
    ..
    QueryPerformanceCounter(&before);
    DrawWorld();
    QueryPerformanceCounter(&after);

    float duration = ((float)after.QuadPart-before.QuadPart ) / ClocksPerSec.QuadPart;

    float FPS=1/duration;
    ..

    So duration is the time between before and after in miliseconds. This is the same Algo like Humus, but a little bit shorter and not the exact one he had written. But if you have questions, look at his posting it will work..
    Greets, Peter

Posting Permissions

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