Page 1 of 1

FPS Counter

Posted: Sat Aug 02, 2003 8:54 am
by Flype
I'm wondering how to perform a FramePerSecond (FPS) test :

I do it this way, is it OK ?

Code: Select all

InitSprite()
InitKeyboard()
SetRefreshRate( 60 )
If OpenScreen( 640, 480, 16, "FPS" )

  Repeat
    
    FrameCounter + 1
    
    If StartDrawing( ScreenOutput() )
      
      DrawingMode(1)
      FrontColor( 255, 255, 255 )
      Locate( 300, 210 ) : DrawText( "fps test" )
      
      Now = GetTickCount_()
      If (Now-Ticks) > 999
        Ticks = Now
        FramePerSec.s = "FPS: " + Str( FrameCounter )
        FrameCounter = 0
      EndIf
      Locate( 2, 2 ) : DrawText( FramePerSec )
        
      StopDrawing()
      
    EndIf
    
    ExamineKeyboard()
    FlipBuffers()
    ClearScreen(0,0,0)
    
  Until KeyboardPushed( #PB_Key_All )

EndIf
End

Posted: Sat Aug 02, 2003 9:34 pm
by fsw
It seems to work here, but if I change the refresh rate to 50 or 70 the program doesn't start (laptop).
If I delete SetRefreshRate it runs at 60 fps - so I suppose it's not good to HARDWIRE the refresh rate, at least for LAPTOPS where the refresh rate is always the same... there is something to learn every day :wink:

Posted: Sun Aug 03, 2003 3:55 am
by Flype
there's many examples posted in this forum which make use of the SetRefreshRate() function... so you're saying i shoudn't use this function Well...
But, because my game needs to be in 60hz for reliable synchro, i'm wondering how can i be sure that my screen is opened in this mode without using SetRefreshRate(). My gfx card accept 640x480 in 60-72-75-85 hz, so...
The answer is, perhaps, that any new screen is opened in 60hz by default :?

Posted: Sun Aug 03, 2003 4:39 am
by Thade
Why don't you use SetFrameRate(60) ?
With SetRefreshRate() you mess in Users hardware what no User likes - some Monitors have to be adjusted and readjusted after they reestablish their usual refreshrate ...
Not a good idea in my view

Posted: Sun Aug 03, 2003 10:23 pm
by hypervox
Have to agree with Thade here. No graphics / games program should deliberately set refresh rates in hardware - if you want to guarantee FPS, setframerate is the way to go.

This doesn't mean that we should'nt be able to take advantage of higher refresh rates if they're available - perhaps a GetRefreshRate command?

Posted: Mon Aug 04, 2003 10:42 pm
by Flype
SetFrameRate(60) and not SetRefreshRate(60) : I confused these two functions. thank you for your explanation.

Posted: Mon Aug 04, 2003 11:07 pm
by Num3
Beware with setrefreshrate!

Some monitor + ati boards need a special hack that locks the monitor frequency at 60hz for usage, so if you force the refresh rate the game won't work...

Had a few problems with that in a beta test i distributed...