Game Development Community

Fonts

by Dan Phillips · in Torque Game Builder · 08/01/2007 (1:45 am) · 10 replies

This is how fonts work right? TGB creates .uft files for fonts and they're used if the font isn't installed on the machine?

When I build my game and play it on a computer that does not have the font that I am using then text doesn't show up. I have the .uft files for all of the fonts I'm using in the fonts directory. dumpFontCacheStatus() lists all of the fonts in the fonts directory. $Gui::fontCacheDirectory is set to "fonts"

#1
08/01/2007 (4:12 am)
Dan,

Before you do a fontbitmapIOEX(), you should perform a populateFontsEX() with the font you want to export into a UFT file.
#2
08/01/2007 (8:10 am)
I'm not doing a fontbitmapIOEX right now, what does it do?

Can someone explain what should be done when you build your game so that your fonts work on every computer?

I can't find either of those functions in the docs. I foudn populateFontCacheRange() but don't understand what it does still.
#3
08/01/2007 (4:46 pm)
Quote:I can't find either of those functions in the docs. I foudn populateFontCacheRange() but don't understand what it does still.

Basically when the actual fonts are not installed on a PC and a given character needs to be displayed of a given font type and size, TGE/TGB will check it's font cache for that char/font/size and then render it.

When fonts are installed, it doesn't need to use the cache (whether it still uses the cache first when available then falls back to installed fonts, I'm not sure...) as it has everything needed to populate the font cache with the character/font/size you requested and render to screen. So if you displayed the text "Hello World" then the font cache would end up containing entries for the letters "HeloWrd".

As it's only added characters that have been used to the font cache, you can end up with a situation where "h" may not be in the cache even though "H" is. Yet a player could type in the chat hud, "hello World" and you'd end up with "h" in a default font type and "ello World" in the correct font type.

populateFontCacheRange() is simply a short-cut method to ensure EVERY (within the range you specify) character from the uni-code set (for the font type and size you specify) is added into the font-cache.

So if you're using for example only A-Z, a-z, 0-9 then you'd need to run

populateAllFontCacheRange(1,128);
writeFontCache();

Note: the above uses populateAllFontCacheRange, which saves specifying the individual font types and sizes. So long as you have .utf files (even if they don't contain the full character set you need) then you can use the "All" version to save time.

dumpFontCacheStatus is another useful command.

You should then have fully populated .utf files with all the characters you need. Obviously for other languages or punctuation you'd need to lookup what range you need to export in the relevant UTF tables.
#4
08/02/2007 (8:41 am)
Thanks Gary! Makes much more sense now. If the uft fonts are in the font cache directory does anything need to be done to load them into the font cache?
#5
08/02/2007 (9:06 am)
You don't need to do anything, the engine will automatically use the cache. That is assuming the .utf files were fully populated at some previous time when the real fonts were available (via commands previously mentioned).
#6
08/02/2007 (9:23 pm)
Thanks. Sure wish things like this were in the documentation.
#7
08/02/2007 (11:12 pm)
In TGB 1.3 the engine would automatically load UFT fonts. This doesn't seem to be the case in TGB 1.5.X... you will have to call importCachedFont manually on each of your cached fonts. I tested this by adding Con::printf calls to all of the font functions. In my test cases TGB ignored UFT fonts and created its own fonts from the installed system fonts. So if you're using a newer version of TGB, I welcome you to try the font tool I posted in the resources section.
#8
08/04/2007 (12:13 pm)
Are you using 1.5.1? I'm using 1.5 and I get the error GFont::importStrip - could not load file './fonts/Franklin Gothic Demi 23.png'! when using importCachedFont

for (%i=6;%i<34;%i++)
	{
		%filename = "./fonts/Franklin Gothic Demi" SPC %i @ ".png";
		importCachedFont("Franklin Gothic Demi", %i, %filename, 0, 0);
	}

I don't want to switch to 1.5.1 because I did some hack to get saving files to work.
#9
08/04/2007 (7:10 pm)
No Dan I'm still using 1.5. I'm hoping that it will also work in 1.5.1 without any changes. What are you trying to do here with this loop? You shouldn't need that many font sizes, and not so close in value (21, 22, 23...?). I use a font size of 80 for almost all of my fonts, and that looks nice to me. My second guess at your problem, would be that there is no "./fonts" directory. But of course I can only speculate.
#10
08/05/2007 (1:57 pm)
Dan,
As Joe stated, without posting a working game in a zip file that can be run, the only thing that can be done to help you is to speculate at what is going on.

If you're able to zip up and post a 1.5 capable game you've created that exhibits the problem you're having, the speculation could be removed and perhaps even yield you a solution or work around.

Until then, good luck figuring it out, sorry you're having problems.

Cheers,
-Justin