Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » OpenLayer font loading uses lots of memory

This thread is locked; no one can reply to it. rss feed Print
OpenLayer font loading uses lots of memory
Vasco Freitas
Member #6,904
February 2006
avatar

Just this line of code:
static TextRenderer normalTextRenderer("Fonts/CHERI.TTF", 55, 35, Rgba(0.0f, 0.0f, 0.9f));

Is taking up about 30MB of memory, and it's a pretty simple font. Is this normal? What can I do about it?

Ceagon Xylas
Member #5,495
February 2005
avatar

I don't think this'd have much to do with it, but what font is it?

Vasco Freitas
Member #6,904
February 2006
avatar

Just some font I got at dafont.com (I don't remember the name), but this seems to happen with all fonts, I tried 4 different fonts. The more complex the font though, the more memory it seems to use. But even the simplest ones I tried occupy 20-30MB.

I'd really appreciate some help on this, the game I'm making isn't supposed to take up more than 32MB :-/

tobing
Member #5,213
November 2004
avatar

Which version of OpenLayer do you use? Compiled with which compiler? Do you use internal text rendering or GlyphKeeper?

Vasco Freitas
Member #6,904
February 2006
avatar

I have a WIP version from about 5-8 months ago (after a certain version globally defined bitmaps stopped appearing, so I've stopped updating since). The compiler is gcc 3.4.2 (mingw-special). I guess I use internal text rendering, because I don't define a GlyphKeeper type.

tobing
Member #5,213
November 2004
avatar

I don't know much about the state of OL of that time... I can only suggest you try to use the current SVN with the most recent allegroGL, and compile OL with define USE_NEW_TTF set, so the internal text renderer will be used instead of GlyphKeeper. That's at least what I do, and I have just checked that my memory consumption grows by about 600kB when I load a TextRenderer object. I have built with MSVC 7.1, but that should not make such a huge difference.

For the problem of globally defined bitmaps disappearing, that's somewhat strange and if it occurs with the current SVN I could try to help finding what's wrong there.

Paul whoknows
Member #5,081
September 2004
avatar

Quote:

Is taking up about 30MB of memory...

How do you know that? how can you measure it?

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Vasco Freitas
Member #6,904
February 2006
avatar

I compare the amount of memory the process uses with and without the font loaded, in the Windows Task Manager. I know that's probably not the best way to do it, but in this case the problem seems obvious.

Druss
Member #7,075
March 2006

I don't know open layer, but could it perhaps be rendering the font to a bitmap, and so needing to store the rendered font and if the font has a lot of characters (excess unicode pages?) or rendered at large size then that might explain it.

Vasco Freitas
Member #6,904
February 2006
avatar

Well, I don't know how OpenLayer stores the font, I don't load the fonts too big in size (55 pixels height), so there's no reason to save them bigger. It's surely not excess unicode pages, they usually don't have many characters. I even tried one font file that's only 9KB large.

Does this happen with anyone else?

Jonatan Hedborg
Member #4,886
July 2004
avatar

If you only have 32 MB of ram to play around with, i would recommend using plain allegro, or something even simpler, as that is a painfully low limit (silly really).

As i understand it, the font is rendered to a texture (which is then rendered as a texture on a quad). I don't think 30MB is that unreasonable. 55 is pretty big, and the texture has to contain all the characters...

tobing
Member #5,213
November 2004
avatar

Vasco: I would offer to have a try to compile your sources on my machine, with my versions of the libraries and try it out. You don't use many other libs, I hope? If you're willing to send me sources and data, just zip them and send my a PM for my mail address.

Vasco Freitas
Member #6,904
February 2006
avatar

Jonatan Hedborg: I meant 32MB of video memory. The font should be on the video memory right? (Hope I'm not saying something stupid)

I think anything above 3MB is unreasonable. A 1024 x 768 image should be about 3,2MB (right?), and all letters of a font that size surely don't take all that up.

tobing: Thanks for offering your help. All your need to do is run this simple code, with the font I've attached:

1#include <OpenLayer.hpp>
2 
3using namespace ol;
4 
5int main() {
6 
7 if(Setup::SetupProgram() == false) {
8 allegro_message("Error loading OpenLayer library!");
9 exit(-1);
10 }
11 
12 if (Setup::SetupScreen(320, 200, WINDOWED, desktop_color_depth()) == false){
13 allegro_message("Error setting graphics mode!");
14 exit(-1);
15 }
16 
17 
18 // Remove this line to compare //
19 static TextRenderer normalTextRenderer("BADABB__.TTF", 55, 35, Rgba(0.0f, 0.0f, 0.9f));
20 
21 while (!key[KEY_ESC]){
22 
23 }
24 
25 return 0;
26}
27END_OF_MAIN()

On my system, with the font loaded the process occupies 54.640MB, without the font loaded, 27.420MB.

Jonatan Hedborg
Member #4,886
July 2004
avatar

hmm. yes, you are correct of course. My bad :)
But how is it possible to know how much is uploaded to the video card? Afaik, there is no way to know how much video memory is used. And i think openlayer/openGL moves around textures if there is no more room on the video card, so you shouldn't worry about it.

tobing
Member #5,213
November 2004
avatar

Tested with your font, it also uses about 600kB extra memory... using GlyphKeeper with pure allegro, it takes 300kB extra memory...

Vasco Freitas
Member #6,904
February 2006
avatar

Are you sure the font was loaded? Because, that's the extra memory I get if the font file isn't there.

I tried with OpenLayer's latest update with no success.

I've attached the project folder I use for the test case, with the Code::Blocks project file. I'd appreciate it if anyone could try it out. :)

EDIT: Anybody? :-/

Go to: