Showing Framerate with DrawText()?

BlitzMax Forums/BlitzMax Programming/Showing Framerate with DrawText()?

Newbie(Posted 2007) [#1]
Does anyone have a function or some code that displays the framerate?


Newbie(Posted 2007) [#2]
I found this here on the forum:

Local FPS_Counter:Int
Local FPS_Counter_Time:Int
Local FPS:Int
FPS_Counter=FPS_Counter+1
If FPS_Counter_time+1000 =< MilliSecs()
FPS=FPS_Counter' <- Frames/Sec
FPS_Counter=0
FPS_Counter_time=MilliSecs()
EndIf
DrawText "Current FPS: "+FPS,20,20

but it doesnt seem to work?


Perturbatio(Posted 2007) [#3]
Graphics 640, 480,0

Local FPS_Counter:Int
Local FPS_Counter_Time:Int
Local FPS:Int





While Not KeyDown(KEY_ESCAPE)
FPS_Counter = FPS_Counter + 1

If FPS_Counter_time+1000 =< MilliSecs()
	FPS=FPS_Counter' <- Frames/Sec
	FPS_Counter=0
	FPS_Counter_time=MilliSecs()
EndIf
DrawText "Current FPS: " + FPS , 20 , 20
Flip
Cls

Wend
End



GfK(Posted 2007) [#4]
Something like this should work (untested tho). All it does is count the number of screen updates, then store the result in a separate var at the end of each second:
Global FramesPerSec:int
Global FrameCounter:int
Global Start:int

While Not KeyDown(KEY_ESCAPE)
  'do stuff
  UpdateFrameCounter()
  DrawText "FPS: " + FramesPerSec,10,10
  Flip
Wend

Function UpdateFrameCounter()
  FrameCounter:+1
  If Millisecs() > Start + 1000
    Start = Millisecs()
    FramesPerSec = FrameCounter
    FrameCounter = 0
  EndIf
End Function



Newbie(Posted 2007) [#5]
@GFX

when I use your version, it remains almost at all times at 61 FPS. sometimes 60 FPS. then again, there is nothing going on right now except some drawtext commands


Perturbatio(Posted 2007) [#6]
that's because the hertz value of the graphic command is at 60 by default, set it to 0 to allow unlimited updates


Newbie(Posted 2007) [#7]
hey man! Thanks!! I will try that! where is the 0 explained in the documentation by the way?


Newbie(Posted 2007) [#8]
oh
my graphics command is:
Graphics 800,600, 1
(1 for fullscreen)
now if I add like you say:
Graphics 800,600, 1, 0

I still get a framerate of 1 (split second) then 60 or 61 constantly


GfK(Posted 2007) [#9]
You'll need to change 'Flip' to 'Flip 0'. (disables vSync, basically).


Newbie(Posted 2007) [#10]
wow ... when i do that! I get a framerate of 3400-3500 ... ????


GfK(Posted 2007) [#11]
Sounds about right...


Newbie(Posted 2007) [#12]
sounds about right (insert shocked face here)??? please explain


GfK(Posted 2007) [#13]
Well, all the code is doing, is drawing a line of text.

Disabling vSync means that your PC is going to redraw the screen as fast as it possibly can, so frame rates of 3000+FPS are not uncommon. Framerate is dependent on hardware, obviously.


Newbie(Posted 2007) [#14]
I must not understand then; i believed the highest framerate was 60 per second for NTSC 50 FPS for PAL regions.


tonyg(Posted 2007) [#15]
The code is measuring the speed of logic cycles not monitor refresh rates.
What release of Bmax are you using? If not BMAX 1.24 you should upgrade.
The documentation for Graphics command states
This value can be 0, 16, 24 or 32 depending on the graphics modes available
so you shouldn't really be setting 1 for 'depth'.


Newbie(Posted 2007) [#16]
I am using the 1.24; oh, and the "1" does into fullscreen, whereas if i use "0" i run windowed ...


tonyg(Posted 2007) [#17]
and the "1" does into fullscreen

... and so does any non-0 number. However, that parm is the depth and *SHOULD* be set to 16,24 or 32.


Newbie(Posted 2007) [#18]
okie dokey!