Fig wrote:How fast is it compared with DrawText()?
It's
much faster!, because you don't need a StartDrawing() and #PB_2DDrawing_Transparent mode which is very slow compared to the Sprite-Lib with DisplayTransparentSprite.
Here my results:
Code: Select all
Characters | Typeface | DrawText
180 3500 FPS 108 FPS
1800 700 FPS 13 FPS
18000 80 FPS <1 FPS
I can only advise against using DrawText in games!
Test code:
Code: Select all
InitSprite()
Enumeration
#Window
#Typeface
#Sprite
#Font
EndEnumeration
IncludeFile "Typeface.pbi" : UseModule Typeface
Declare FPS()
OpenWindow(#Window, 0, 0, 700, 520, "Typeface Example", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window), 0, 0, 0, #PB_Screen_NoSynchronization)
SpriteQuality(#PB_Sprite_BilinearFiltering)
UsePNGImageDecoder()
UsePNGImageEncoder()
LoadTypeface(#Typeface, "Tahoma20.tf")
LoadFont(#Font, "Tahoma", 16)
Define Characters = 18000
Define Typeface = #False;#True;
Repeat
ClearScreen($000000)
SpriteBlendingMode(#PB_Sprite_BlendSourceAlpha, #PB_Sprite_BlendInvertSourceAlpha)
ResetTypefaceStyles(#Typeface)
DisplayTypeface(#Typeface, 0, 0, "FPS: "+Str(FPS()))
RandomSeed(0)
If Typeface
For I = 1 To Characters/60
DisplayTypeface(#Typeface, 10, 20+Random(480), "Grumpy wizards make toxic brew For the evil Queen And Jack.")
Next
Else
If StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(FontID(#Font))
For I = 1 To Characters/60
DrawText(10, 20+Random(480), "Grumpy wizards make toxic brew For the evil Queen And Jack.")
Next
StopDrawing()
EndIf
EndIf
FlipBuffers()
Until WindowEvent() = #PB_Event_CloseWindow
Procedure.i FPS()
Static Count.i, Time.i, FPS.i
Protected CurrentTime
CurrentTime = ElapsedMilliseconds()
If Time = 0 : Time = CurrentTime : EndIf
If CurrentTime - Time > 1000
FPS = 1000 * Count / (CurrentTime - Time)
Time = CurrentTime
Count = 0
EndIf
Count + 1
ProcedureReturn FPS
EndProcedure
[/size]