custom BitMap fonts vs. DrawText()?

Advanced game related topics
vanleth
User
User
Posts: 79
Joined: Sat Jun 28, 2003 4:39 am
Location: Denmark - Valby

custom BitMap fonts vs. DrawText()?

Post by vanleth »

I can't beat PB's DrawText() speed with the DisplaySprite() command in fullscreen for making gamefonts.
My approach was to have 1 sprite containing all the letters, then clip the sprite for a specific letter.
Anyone have a good workaround to do this trick faster?

Best regards
Van
vanleth
User
User
Posts: 79
Joined: Sat Jun 28, 2003 4:39 am
Location: Denmark - Valby

Post by vanleth »

I'll better post some examples.

Here is the font sprite

Image

And here is some test code. It's very noticeable that my routine is slow

Code: Select all

InitSprite() : InitKeyboard()

OpenScreen(800,600,16,"Bitmap Font")
; font sprite letters is 6 in width and 10 in height
LoadSprite(0, "debugfont.bmp" , 0 )

Procedure bitmap_text(x.l, y.l, string_buffer.s)
  a=0
  Repeat
    buff.b = PeekB(@string_buffer+a)
    ClipSprite(0,(buff-32)*6, 0, 6, 10)
    DisplaySprite(0, x+(a*6), y)
    a+1
  Until buff = 0
EndProcedure

Repeat
  FlipBuffers() : ClearScreen(0,0,0)

  old_time = TimeGetTime_()
  For a = 0 To 2000
    bitmap_text(100,100,"Bitmap Font")
  Next
  bitmapfont_time = TimeGetTime_() - old_time
  
  old_time = TimeGetTime_()
  StartDrawing(ScreenOutput())
  DrawingMode(1) : FrontColor(200,200,200)
    For a = 0 To 2000
      Locate(100, 112) : DrawText("Fred's Font")
    Next  
  pbfont_time = TimeGetTime_() - old_time
  
  ; show results
    Locate(0,0) : DrawText("Bitmap "+Str(bitmapfont_time))
    Locate(0,12) : DrawText("PureBasic "+Str(pbfont_time))
  StopDrawing()

  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

I have noticed this as well.. too bad PB doesn't support TTF fonts..
(at least, I didn't get them to work)

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
chris_b
Enthusiast
Enthusiast
Posts: 103
Joined: Sun Apr 27, 2003 1:54 am

Post by chris_b »

vanleth wrote:here is some test code. It's very noticeable that my routine is slow
Your code doesn't account for the time taken to do StartDrawing() and StopDrawing() - if you can avoid using any 2DDrawing stuff in your main loop then the font sprite method will be probably as fast
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

chris_b wrote:
vanleth wrote:here is some test code. It's very noticeable that my routine is slow
Your code doesn't account for the time taken to do StartDrawing() and StopDrawing() - if you can avoid using any 2DDrawing stuff in your main loop then the font sprite method will be probably as fast
No no, Chris_b.. If you'd look at the code, you'd see that he is not using any Start/Stop-drawing commands during the bitmap_text test... I have come to the same results as Vanleth as well... If only we could get almost as fast text as the standard one, with TTF fonts, then we could forget most of the bitmap fonts.. :) (unless you want some colored fonts)

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

A NOTE, Talking about speed:

MSWinAPI TimeGetTime_() and GetTickCount_() funcs return samething, but this last is much faster :wink:
Last edited by Psychophanta on Wed Oct 29, 2003 12:17 pm, edited 1 time in total.
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post by LarsG »

Psychophanta wrote:A NOTE, Talking about speed:

MSWinAPI TimeGetTime_() and GetTickCount_() funcs do samething, but this last is about twice faster :wink:
Yeah.. I used GetTickCount_() when I tested the speed...
(but in this example, it's not really that important..)

-Lars

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I know, but i am really obsessionate 8O with speed .
chris_b
Enthusiast
Enthusiast
Posts: 103
Joined: Sun Apr 27, 2003 1:54 am

Post by chris_b »

LarsG wrote:If you'd look at the code, you'd see that he is not using any Start/Stop-drawing commands during the bitmap_text test
What I am suggesting is that

Code: Select all

Repeat

  FlipBuffers()
  ClearScreen(0,0,0)

  Display_some_bitmap_text_using_sprites

  ExamineKeyboard() 

Until KeyboardPushed(#PB_Key_Escape)
is probably similar speed to

Code: Select all

Repeat

  FlipBuffers()
  ClearScreen(0,0,0)

  StartDrawing(ScreenOutput())
    Draw_some_text
  StopDrawing()

ExamineKeyboard() 

Until KeyboardPushed(#PB_Key_Escape)
due to the time taken for the Start/Stop drawing functions.

Of course it depends on the amount of text displayed at a time, whether you use DrawSprite or DrawTransparentSprite, etc. But for game use where you display small amount of text on the screen (like score and lives remaining) I think vanleth's bitmap_text function is fine.

If you are displaying more text at a time - like for example the speech boxes in RPG style games - then you can maybe use the bitmap_text function to draw to a seperate sprite once with the usebuffer function and then only display that one sprite within the main loop.
vanleth
User
User
Posts: 79
Joined: Sat Jun 28, 2003 4:39 am
Location: Denmark - Valby

Post by vanleth »

Well my test code was just to point out that Freds DrawText() routines are hard to beat speed wise.

Actually it got me abit curious on how the DrawText() command works internally.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Don't you prefer to ask yourself how work internally ClipSprite() and DisplaySprite()?
Might be DrawText() is good made, but ClipSprite() and DisplaySprite() too slow :twisted: .
Post Reply