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

Thread: FPS???

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2001
    Posts
    5

    FPS???

    Hello!

    I've trubles with figuring out FPS. I do it like this:
    i have gloabal variables:
    LARGE_INTEGER freq;

    float framestart,frameend,frametime,fps;

    in init i do:
    QueryPerformanceFrequency(&freq)
    and get time with function:
    float precisetime ()
    {
    QueryPerformanceCounter(&time);
    return (float)time.QuadPart/(float)freq.QuadPart;
    }

    In glutIdleFunc i do:
    framestart=precisetime();
    draw_scene;
    frameend=precisetime();
    frametime=framestart-frameend;
    fps=1/frametime;

    Now, why is always frametime=0? (ok, i render only 1 cube, but hell, even THAT takes some time). What am I doing wrong?

    10x for help!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: FPS???

    try fps=1.0f/frametime;

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2001
    Posts
    5

    Re: FPS???

    Thanks...but I tried that already - no dice. Like I said, the problem is because frametime is always 0...so how should I relay on it to calulate moves for cubes etc? (with moveby=movepersecond*frametime)

    [This message has been edited by mtrooper (edited 01-20-2001).]

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: FPS???

    Why? Because those 64 bit values need the precision of a double, not a float. When you cast it to a float, you are throwing away up to 29 bits of precision!


    [This message has been edited by DFrey (edited 01-20-2001).]

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2001
    Posts
    5

    Re: FPS???

    Thank you thank you thank you thank you thank you...I knew I should first get a hang of C++...damn. Really, thanks!

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: FPS???

    I know why I'm always running on millisecond base... However I can't believe that only the loss of precision will drop it to zero. When the time gets really small, it will be round off to zero while the cast I think. Shouldn't that lead to an exception (or does the fpu just ignore that?)?
    And if not, the floats suffice for really a large number of fps. There's some strange thing in his precisetime function I think. Gonna look in my code.

  7. #7
    Member Contributor
    Join Date
    Jan 2001
    Posts
    87

    Re: FPS???

    Originally posted by Michael Steinberg:
    Shouldn't that lead to an exception (or does the fpu just ignore that?)?
    Dividing by zero is ignored because in app initialzation (in glut32.dll module I think) the divide-by-zero exception is turned off.
    It is done because many of OpenGL floating operations (like x/w) would cause an exception.

  8. #8

    Re: FPS???

    I did mine a little differently. For starters, I used GetTickCount() rather than the high precision one you guys are using. I see no need for high precision timing just for a simple FPS counter. GetTickCount() returns a DWORD value in milliseconds. My code is this:

    currenttime=GetTickCount();
    frames++;
    if ((currenttime-1000)>=starttime) //after 1 second
    {
    fps=frames; //set fps=# of frames after 1 second
    starttime=currenttime; //reset the timer
    frames=0; //set frame counter back to zero
    }
    ...draw the scene...

    [This message has been edited by element (edited 02-11-2001).]

  9. #9
    Senior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Nice, France
    Posts
    201

    Re: FPS???

    On some computers, the counter you query with GetTickCount has a very poor accuracy. The result was that my app that used it raised a "division by 0" exception when I did 1.0f/frametime. At best, if you expect that and test the frametime before the division, you won't get any framerate at all.

  10. #10
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: FPS???

    QueryPerformanCeounter returns zero if no performace counter is available. Maybe you don't have a performance counter...? ( )

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean