FPS Counter

Advanced game related topics
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

FPS Counter

Post 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
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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:

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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 :?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Post 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
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
hypervox
User
User
Posts: 48
Joined: Mon Apr 28, 2003 10:02 am
Location: UK
Contact:

Post 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?
PC 1:AMD Athlon XP 2000,Geforce 2 MX400 64Mb, Windows 2000 :D
PC 2:Intel P3 1ghz, Nvidia Vanta 16Gb, Windows 2000 :)
Registered Purebasic User :D

PureBasic Game Creation Site
http://www.hypervox.co.uk/PureBasic/
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

SetFrameRate(60) and not SetRefreshRate(60) : I confused these two functions. thank you for your explanation.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

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