Page 1 of 2

Draw Text really slow

Posted: Wed Mar 30, 2011 5:03 pm
by Brujah
Since we switched from 4.20 to 4.51 displaying text is realllllyyy slow.
Why does pb not use opengl to display text?
Or what else is the reason that its that slow?

We solved it as a workaround by drawing on a picture and display it afterwards. But I cannot understand why I has slowed down that much.

Re: Draw Text really slow

Posted: Wed Mar 30, 2011 6:34 pm
by IceSoft
You can choose OpenGL as subsystem (Maybe it is better for you?)

Re: Draw Text really slow

Posted: Wed Mar 30, 2011 7:26 pm
by Brujah
Where would I find information about subsystems and how to use them?
Searched the documentation but couldn't find anything :(

Re: Draw Text really slow

Posted: Wed Mar 30, 2011 9:14 pm
by idle
under compiler options just type in the subsystem opengl

Re: Draw Text really slow

Posted: Wed Mar 30, 2011 10:23 pm
by Brujah
when I compile the game with this command:

Code: Select all

pbcompiler -s "opengl" laby.pb
Drawing text is still slow.
Should it work by using DrawText as usual?

Re: Draw Text really slow

Posted: Wed Mar 30, 2011 10:46 pm
by idle
You could try using opengl text functions, I've never used them on linux though.

or just draw text to an img and make a sprite from it

Code: Select all

     ;calculate img size needed to hold the text 
     timg = CreateImage(#PB_Any,1,1)
     StartDrawing(ImageOutput(timg))
        DrawingFont(FontID(tf))  
       width = TextWidth(words)
       height = TextHeight(words)  
     StopDrawing()  
     FreeImage(timg) 
     
    img = CreateImage(#PB_Any,width,height)
    
     StartDrawing(ImageOutput(img))
        DrawingFont(FontID(font))  
        DrawText(0,0,words,color)
     StopDrawing()


Re: Draw Text really slow

Posted: Fri Apr 01, 2011 7:32 pm
by Brujah
Thanks. This works good and is really fast.

Re: Draw Text really slow

Posted: Wed May 18, 2011 1:01 pm
by Didelphodon
I'm also having this DrawText performance problem but in my case the mentioned workarounds are an absolutely no-go as my data (text) is highly dynamical.
Any ideas for what's the reason behind this performance-issue or furthermore, how it could be solved?

Cheers,
Didel.

Re: Draw Text really slow

Posted: Wed May 18, 2011 9:14 pm
by idle
if it's to slow to draw text to an image and create a sprite from it dynamically
then create a character array of the font at start up and save the sprites in the array, then just look them up.

If that's not suitable because you need different fonts sizes and colors
you can dynamically create and cache glyphs as required using a map with a structure of the sprite and reference count
keying it with with the character font size color.

Re: Draw Text really slow

Posted: Thu May 19, 2011 8:17 pm
by Didelphodon
idle wrote:if it's to slow to draw text to an image and create a sprite from it dynamically
then create a character array of the font at start up and save the sprites in the array, then just look them up.

If that's not suitable because you need different fonts sizes and colors
you can dynamically create and cache glyphs as required using a map with a structure of the sprite and reference count
keying it with with the character font size color.
Hm, that's kinda ... weird workaround for something that actually shouldn't be an issue at all.

Re: Draw Text really slow

Posted: Fri May 20, 2011 1:44 am
by idle
I don't think it's particularly unusual, OpenGL and SDL alone don't support fonts directly.

Re: Draw Text really slow

Posted: Fri May 20, 2011 9:06 am
by Shield
Yes, sprite fonts are the way to go. :)

The problem with DrawText being slow is that there is no hardware support
for that function. If you draw each character you need on a sprite and then
display them you'll get way more speed since sprites are hardware accelerated (Sprite3D).

However DirectX 10 offers a great deal of routines to display and modify text really fast
but that's probably not an option for you if you want to stay as compatible as possible to other systems and since this thread is in the Linux sub forum.

OpenGL does have native sprite font support if I remember correctly (so does DirectX if you use the libraries that provide additional functionality),
but it's quite limited. If you draw them on your own you'll have more control. :)


(Edit: if you're actually drawing on a screen)

Re: Draw Text really slow

Posted: Fri May 20, 2011 10:13 am
by Didelphodon
Ok, maybe some kind of misunderstanding - eventually I didn't make myself clear enough, my excuses for that.
I'm just using the basic 2d-drawing capabilities. What for? For my actual project I need a bunch of special/enhanced controls/gadgets - on Linux, Windows and MacOS as well. So I'm kinda doing a cross-platform-gadgetlibrary, so to say - as a subproject. So no directx, opengl and co.

Cheers,
Didel.

Re: Draw Text really slow

Posted: Fri May 20, 2011 10:20 am
by Shield
Well for regular controls the speed of DrawText should be more than sufficient. :?
When exactly does it start feeling sluggish?

Re: Draw Text really slow

Posted: Fri May 20, 2011 10:27 am
by Didelphodon
Any drawing-functions work fast as long as I don't use DrawText. When I include the text-drawing performance drops that massively that the window actually stops responding as it has no time left to handle the waiting messages, at all.