Huge memory increase when using FreeType Font

BlitzMax Forums/BlitzMax Programming/Huge memory increase when using FreeType Font

Hezkore(Posted 2010) [#1]
Why is there such a huge increase in memory when using FreeType Font?
From about 10000K ~ 15000K to 25000K, is there any alternative to FreeTypeFont or way of lowering the memory usage?

Last edited 2010


Gabriel(Posted 2010) [#2]
When did 10 megabytes become a "huge increase in memory"? I don't know what "FreeType Font" is, but if you're loading a bitmap font, a 2048x1024 texture, with mipmaps, would be in the ballpark of that amount of memory. So are you loading a font that would be too big to fit all characters on a 1024x1024 texture?

Last edited 2010


Hezkore(Posted 2010) [#3]
Well seeing as I'm working on a lightweight media player, 10mb of memory is quite the increase (almost double the amount of memory) ;)
And I'm on about brl.FreeTypeFont which is the default Module for drawing fonts using Max2D's DrawText function.
LoadImageFont(), SetImageFont() etc. all comes from brl.FreeTypeFont.


Gabriel(Posted 2010) [#4]
You didn't answer my question. LoadImageFont sounds as though the answer to "if you're loading a bitmap font" is yes, but are you requesting a font size that would struggle to fit all the glyphs on a 1024x1024 texture?


JoshK(Posted 2010) [#5]
Use the BLide font machine module. It will also provide correct text sizing. The built-in BMX text functions don't display fonts correctly.


skidracer(Posted 2010) [#6]
Josh, perhaps it would be helpful to the Blitz community if you were to suggest a fix for the BlitzMax implementation, from a quick browse this morning it looks like brl.freetype should be using the FT_Set_Char_Size command in place of the FT_Set_Pixel_Sizes function?


Hezkore(Posted 2010) [#7]
@JoshK
BLide font machine doesn't support .ttf files which is want I need to load. :/


JoshK(Posted 2010) [#8]
Use FT_Set_Char_Size(face, 0, size * 64, 0, 96), where size is the font size. I don't use that pixel command.

The offset for each character is given by these:
face->glyph->metrics.horiBearingX/64;
face->glyph->metrics.horiBearingY/64;

The spacing for a character is this:
face->glyph->metrics.horiAdvance/64.0;

The width and height are given by the bitmap.width and bitmap.rows.

So for each character:
Draw a rect at x + offsetx, y+offsety that is width x height. Then add the spacing to x and draw the next character.

Last edited 2010