fps counter
Blitz3D Forums/Blitz3D Programming/fps counter
| ||
Please tell me if this is correct. I have readings of arond 450 fps according to this code. I know there's not much happening and a 128M graphics card helps, but isn't 400+ a bit much?ClearWorld Graphics3D 800,600,32,0 SetBuffer BackBuffer() AmbientLight 200,200,200 redcube=CreateCube() PositionEntity redcube,10,10,10 EntityColor redcube,200,10,10 greencube=CreateCube() PositionEntity greencube,5,5,15 EntityColor greencube,10,200,10 bluecube=CreateCube() PositionEntity bluecube,15,5,15 EntityColor bluecube,10,10,200 toplight=CreateLight(1) PositionEntity toplight,-20,40,20 PointEntity toplight,redcube sidelight=CreateLight(1) PositionEntity sidelight,30,10,10 PointEntity sidelight,redcube cam=CreateCamera() CameraViewport cam,0,0,800,600 PositionEntity cam,10,5,10 PointEntity cam,redcube MoveEntity cam,0,0,-10 timer#=MilliSecs() While Not KeyDown(1) TurnEntity redcube,1,0,0 TurnEntity greencube,0,1,0 TurnEntity bluecube,0,0,1 UpdateWorld RenderWorld frames=frames+1 fps#=(MilliSecs()-timer#)/1000 fps#=(frames/fps#) Text 0,220,"Frames: "+frames+" " Text 0,240,"Seconds: "+(MilliSecs()-timer#)/1000+" " Text 0,260,"Frames Rendered Per Second: "+fps+" " Flip Wend ClearWorld EndGraphics End |
| ||
| FPS means Frame Per Seconds. If you do this at each loop: fps#=(MilliSecs()-timer#)/1000 this is not frame per seconds. You should check fps only once per seconds, that is, each time your timer# variable reach the value of 1000 (because 1000 millisecs = 1 sec), then show the new fps. example: local ms_passed ;milliseconds passed local tot_frames ;total frames passed local fps ;fps printed on screen ms_passed = millisecs() while not keydown(1) tot_frames = tot_frames + 1 if (millisecs() - ms_passed) >= 1000 then ; a second is passed ! fps = tot_frames ;store the new fps value tot_frames = 0 ;reset total frames ms_passed = millisecs() ;reset msecs counter endif updateworld renderworld text 0,0,fps flip wend end Sergio. |
| ||
| I see what you mean. Heres the code again, with your framerate counter included (I hope correctly) However now I am getting results of 700+ Is this right???
ClearWorld
Graphics3D 800,600,32,0
SetBuffer BackBuffer()
AmbientLight 200,200,200
redcube=CreateCube()
PositionEntity redcube,10,10,10
EntityColor redcube,200,10,10
greencube=CreateCube()
PositionEntity greencube,5,5,15
EntityColor greencube,10,200,10
bluecube=CreateCube()
PositionEntity bluecube,15,5,15
EntityColor bluecube,10,10,200
toplight=CreateLight(1)
PositionEntity toplight,-20,40,20
PointEntity toplight,redcube
sidelight=CreateLight(1)
PositionEntity sidelight,30,10,10
PointEntity sidelight,redcube
cam=CreateCamera()
CameraViewport cam,0,0,800,600
PositionEntity cam,10,5,10
PointEntity cam,redcube
MoveEntity cam,0,0,-10
ms_passed = MilliSecs()
Local fps
While Not KeyDown(1)
TurnEntity redcube,1,0,0
TurnEntity greencube,0,1,0
TurnEntity bluecube,0,0,1
If (MilliSecs() - ms_passed) >= 1000
ms_passed = MilliSecs()
fps = tot_frames
tot_frames = 0-1
EndIf
tot_frames = tot_frames + 1
UpdateWorld
RenderWorld
Text 0,260,"Frames Rendered Per Second: "+fps+" "
Flip
Wend
ClearWorld
EndGraphics
End
|
| ||
Using this FPS counter (with Flip False):;Framecounter-------------------------------------------- Framecounter_counter=Framecounter_counter+1 If Framecounter_time=0 Then Framecounter_time=MilliSecs() If Framecounter_time+1001 <MilliSecs() Then Framecounter_framerate=Framecounter_counter Framecounter_counter=0 Framecounter_time=MilliSecs() EndIf I get an FPS number of ~750. So your counter should be correct. :) |
| ||
| great thanks! |