Page 2 of 2

Re: Draw Text really slow

Posted: Fri May 20, 2011 10:51 am
by Shield
hmm strange... :?

Can't help further though because it seems to be a PB / Linux related issue (as you said before
the later versions the performance was better) and I don't use Linux.

Sorry.

Re: Draw Text really slow

Posted: Fri Jul 22, 2011 4:05 am
by idle
If you think about it it's reasonable to assume Drawtext will be slow when it's using true type fonts.
There's a lot of math going on to create the symbol. Make a glyph cache with a map

something like this

Code: Select all

Structure glyph 
  glyph.i
  refcount.i  
  width.i
  height.i
EndStructure     

Global NewMap glyphs.glyph() 

Procedure GlyphCache()
tf=LoadFont(#PB_Any,"arial",14,0)
For a = 32 To 126 
  timg = CreateImage(#PB_Any,1,1)
  StartDrawing(ImageOutput(timg))
  DrawingFont(FontID(tf))
     width = TextWidth(Chr(a))
     height = TextHeight(Chr(a))
  StopDrawing()
  FreeImage(timg)
  If width And height 
     glyphs(Chr(a))\glyph = CreateImage(#PB_Any,width,height,24)
     StartDrawing(ImageOutput(glyphs(Chr(a))\glyph))
       DrawingMode(#PB_2DDrawing_Default)
       DrawingFont(FontID(tf))
       DrawText(0,0,Chr(a),RGB(255,0,0),0)
     StopDrawing()
     glyphs(Chr(a))\width = width 
     glyphs(Chr(a))\height = height 
   EndIf
 Next 
EndProcedure 

Procedure myDrawtext(output.i,text.s,x,y)
  Protected chr.s
  len = Len(text)
  If StartDrawing(output) 
    For a = 1 To len 
      chr = Mid(text,a,1)
      DrawImage(ImageID(glyphs(chr)\glyph),x,y)
      x+glyphs(chr)\width 
    Next
    StopDrawing()
  EndIf  
EndProcedure  

GlyphCache() 
OpenWindow(0,0,0,800,600,"test")

Repeat 
  ev = WindowEvent()
  myDrawtext( WindowOutput(0),"test",Random(700)+50,Random(500)+50)
  Delay(20)
Until ev =#PB_Event_CloseWindow   


Re: Draw Text really slow

Posted: Sat Jul 23, 2011 4:34 pm
by Brujah
We did a similar solution for our game.
We create sprites for sentences as we do not have THAT many of them.
And we save them in a map as well so they have to be created only once.
At gamestart we create the most used once so ingame we do not get any more slowdowns.

Problem here still is that it looks strange in a lot of places as antialiasing and stuff is missing. (No problem on black background but in f.e. the tile where we display on a scrolling background it looks strange)
I solved that by displaying the sprite in black first with offsets of -1 in all directions.
But still it does not look as good as it should :(