Draw Text really slow

Linux specific forum
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Draw Text really slow

Post 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.
User avatar
IceSoft
Addict
Addict
Posts: 1698
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Draw Text really slow

Post by IceSoft »

You can choose OpenGL as subsystem (Maybe it is better for you?)
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Re: Draw Text really slow

Post by Brujah »

Where would I find information about subsystems and how to use them?
Searched the documentation but couldn't find anything :(
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Draw Text really slow

Post by idle »

under compiler options just type in the subsystem opengl
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Re: Draw Text really slow

Post 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?
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Draw Text really slow

Post 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()

Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Brujah
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Nov 03, 2003 7:45 pm
Location: Germany
Contact:

Re: Draw Text really slow

Post by Brujah »

Thanks. This works good and is really fast.
User avatar
Didelphodon
PureBasic Expert
PureBasic Expert
Posts: 450
Joined: Sat Dec 18, 2004 11:56 am
Location: Vienna - Austria
Contact:

Re: Draw Text really slow

Post 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.
Go, tell it on the mountains.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Draw Text really slow

Post 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.
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Didelphodon
PureBasic Expert
PureBasic Expert
Posts: 450
Joined: Sat Dec 18, 2004 11:56 am
Location: Vienna - Austria
Contact:

Re: Draw Text really slow

Post 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.
Go, tell it on the mountains.
User avatar
idle
Always Here
Always Here
Posts: 6026
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Draw Text really slow

Post by idle »

I don't think it's particularly unusual, OpenGL and SDL alone don't support fonts directly.
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Draw Text really slow

Post 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)
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Didelphodon
PureBasic Expert
PureBasic Expert
Posts: 450
Joined: Sat Dec 18, 2004 11:56 am
Location: Vienna - Austria
Contact:

Re: Draw Text really slow

Post 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.
Go, tell it on the mountains.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Draw Text really slow

Post by Shield »

Well for regular controls the speed of DrawText should be more than sufficient. :?
When exactly does it start feeling sluggish?
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
User avatar
Didelphodon
PureBasic Expert
PureBasic Expert
Posts: 450
Joined: Sat Dec 18, 2004 11:56 am
Location: Vienna - Austria
Contact:

Re: Draw Text really slow

Post 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.
Go, tell it on the mountains.
Post Reply