custom BitMap fonts vs. DrawText()?
custom BitMap fonts vs. DrawText()?
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
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
I'll better post some examples.
Here is the font sprite

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

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)
I have noticed this as well.. too bad PB doesn't support TTF fonts..
(at least, I didn't get them to work)
-Lars
(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
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..chris_b wrote: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 fastvanleth wrote:here is some test code. It's very noticeable that my routine is slow
-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
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
A NOTE, Talking about speed:
MSWinAPI TimeGetTime_() and GetTickCount_() funcs return samething, but this last is much faster
MSWinAPI TimeGetTime_() and GetTickCount_() funcs return samething, but this last is much faster
Last edited by Psychophanta on Wed Oct 29, 2003 12:17 pm, edited 1 time in total.
Yeah.. I used GetTickCount_() when I tested the speed...Psychophanta wrote:A NOTE, Talking about speed:
MSWinAPI TimeGetTime_() and GetTickCount_() funcs do samething, but this last is about twice faster
(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
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
What I am suggesting is thatLarsG 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
Code: Select all
Repeat
FlipBuffers()
ClearScreen(0,0,0)
Display_some_bitmap_text_using_sprites
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)Code: Select all
Repeat
FlipBuffers()
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
Draw_some_text
StopDrawing()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)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.
- Psychophanta
- Always Here

- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:

