Recent

Author Topic: BGLFont with multiple labels  (Read 3056 times)

piola

  • Full Member
  • ***
  • Posts: 124
  • Lazarus 2.2, 64bit on Windows 8.1 x64
BGLFont with multiple labels
« on: April 05, 2024, 12:55:36 pm »
Hello,

if I have lots of labels, about 100, which I want to draw with the great BGLFont.TextOut function, is it (with respect to memory usage and performance) better to have my own TBGRATextEffectFontRenderer, or doesn't that matter?

Am I correct assuming that I need one instance of TBGRATextEffectFontRenderer per different font family, font size, and font style?

Sorry for this dumb question. I couldn't find a documentation/reference on how to use BGLFont, except for the announcement that it is available now.

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: BGLFont with multiple labels
« Reply #1 on: April 05, 2024, 05:44:18 pm »
Hello Piola,

I am glad to see your interest in using OpenGL fonctions of BGRABitmap.  :)

When you create the IBGLFont using the BGLFont function and supply your own font renderer, there is an additional parameter to specify whether the renderer is owned by the font. It is perfectly find to share the renderer. To do so, you need to set the ARendererOwned parameter to False so that it won't get freed multiple times.

Regarding memory, there will be slightly less memory used when sharing the rendered, so it is advisable to share it. The instance of a renderer though doesn't use much memory.

The textures of the letters are created and stored by the IBGLFont object. What matters most is to have fewer IBGLFont object. This will use less memory and require less texture creations.

So if possible, when labels use the same font, it is better that they use the same IBGLFont object. If you need various fonts but do not know in advance which ones, I suggest to have list of cached fonts.

Indeed, there isn't much documentation on this subject. You can find some examples in the test/test4lcl_opengl folder, where they basically have only one IBGLFont instance.

Warm regards
Conscience is the debugger of the mind

piola

  • Full Member
  • ***
  • Posts: 124
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: BGLFont with multiple labels
« Reply #2 on: April 09, 2024, 02:29:42 pm »
Thank you very much for your comprehensive answer. I see that I misunderstood the concept anddo  understand now where the glyphs are cached: not in the renderer :D

About the IBGLFont objects: I will, of course, follow your recommendation to cache them. It is obvious that I need an instance for each distinct font name, but how about font size, font style (bold, italics) and color? Do they all need their own IBGLFont? Regarding font style, I'd assume "yes". Font size should also be handled differently, but color shouldn't make a difference. Is this interpretation correct?

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: BGLFont with multiple labels
« Reply #3 on: April 09, 2024, 10:34:24 pm »
You're welcome.  :)

About the name and style, indeed you need a different IBGLFont. Regarding the parameters, your interpretation is correct.

Regarding the color, in the simple case (without effects like outline), you can initialize the font without color (implicitly white). When drawing text with TextOut, you can supply a color that the text will be multiplied with. White being neutral, when multiplied it will give you the chosen color.

Regarding the size, you have a Scale property that can be used to adjust the font size. Though the quality may not be good. For example, if the Scale is 2, it means each texture pixel will be stretched on a 2x2 square. Downsizing (with a scale smaller than 1) may look good in most cases.

Regards
Conscience is the debugger of the mind

piola

  • Full Member
  • ***
  • Posts: 124
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: BGLFont with multiple labels
« Reply #4 on: April 10, 2024, 09:22:56 am »
Great. Thank you very much  :)

 

TinyPortal © 2005-2018