Game Development Community

Import/exportCachedFont() questions

by Alex Rice · in Torque Game Builder · 06/14/2006 (12:34 pm) · 37 replies

Search for importCachedFont and it's only mentioned here: tdn.garagegames.com/wiki/TorqueUnicode

Nobody is discussing it in the forums, apparently. Maybe not a lot of people know about this feature because it sounds quite useful to me. I did some testing (see 3.) but am unclear about the intended usage of this font system:

1. can importCachedFont() be used to create a bitmap font that at runtime the original font is not required to be installed on the user's computer? i.e. I have a cool quirky font named "XYZ" and I want to exportCachedFont() render it up and make it look cool, then in the game load that image with importCachedFont() then the user does not need font "XYZ" installed because torque has the bitmap image. Please say yes that is the intent!

2. If it's not the intent then I guess it can only be used to decorate and touch up fonts which the user has installed on their system. It's hard to make Arial and Times look cool though, so that would suck.

3. Any torquescript code examples how to round-trip export/touch-up/import a font? I managed to get a font loaded, characters cached, and exported to a .png and it looks great. But the font cache directory, and the importing step is giving me troubles.

thanks
[edit for spelling and formatting]
Page «Previous 1 2
#1
06/14/2006 (1:10 pm)
Have you seen this thread: www.garagegames.com/mg/forums/result.thread.php?qt=27090

I know it's not exactly the same as you can't easily specify kerning and so-on, but it works a treat and doesn't require any engine changes.

Edit -> And for touching up fonts, try this: juicyfonts.mysite.wanadoo-members.co.uk/ I've only tinkered with it, but should be much easier than fiddling about in Photoshop.
#2
06/14/2006 (2:07 pm)
Thanks Philip- that definitely is a good alternative method. import/exportCachedFont() would be superior though because then you could use the font with either GUI objects or with custom text objects like t2dTextObject
#3
06/14/2006 (7:14 pm)
Well I re-read the TDN article I referenced, and answered my own questions:
Quote:For maximum compatibility on shipping games, Torque's font rendering code implements a caching feature. This allows fonts to be quickly rendered from pre-generated textures for each character, as well as allowing games to use fonts which may not be installed on the user's computer (or even customized fonts!).
I'll keep experimenting with it.
#4
06/14/2006 (7:27 pm)
I just realized how cool the font system is in Torque!!! I can use a weird-ass font in my game, run it once to generate the .uft file in common\data\fonts, then I can uninstall the font, and my game still runs fine and renders all the characters correctly. way cool. importing/exporting pre- rendered fonts is an issue for another day tho.
#5
06/20/2006 (9:07 am)
@Alex, any more information on what you've found as far as the procedure to get your own fonts in?
#6
06/20/2006 (1:03 pm)
Rodney, no haven't been able to get it to work yet. However, Kevin Ryan said in another thread that they used this technique in Puzzle Poker! So hopefully he will drop some hints but of course that's up to him :-)
#7
06/20/2006 (11:17 pm)
I've been a little busy - very minor surgery for my son. If all goes well I'll post here in the next couple days with some notes on the steps we took to get the custom fonts into Puzzle Poker.
#8
06/20/2006 (11:20 pm)
@Kevin - No problem , hope your sons minor surgery goes well. Look forward to hearing your solution.
#9
06/30/2006 (9:10 am)
Okay is some utility script for Puzzle Poker that we used with the import/export stuff:

function populateFonts()
{
   %font = "Arial";
   %sizes = "18 24 32 36";

   // ---
   for (%i = 0; %i < getWordCount(%sizes); %i++)
      populateFontCacheRange(%font, getWord(%sizes, %i), 32, 126);

   writeFontCache();
}

function fontbitmapIO(%import)
{
   %pngdir = "pngs/";
   %fontdir = "./common/ui/cache/";

   %font = "Arial";
   %sizes = "18 24 32 36";

   // ---
   for (%i = 0; %i < getWordCount(%sizes); %i++)
   {
      %size = getWord(%sizes,%i);

      %weight = 3;
//      %weight = 0;

      %fileName = %fontdir @ %pngdir @ %font SPC %size @ ".png";
      if (%import)
         importCachedFont(%font, %size, %fileName, %weight, 0);
      else
         exportCachedFont(%font, %size, %fileName, %weight, 0);
   }

   writeFontCache();
}

First we would call populateFonts() to create the font with the different sizes and characters we need in the cache.

Then we'd call fontbitmapIO(false) to export the font into a png file. The weight value was the clear space buffer left around each char to give you room to add outlining/whatever on each char within photoshop.

Once we were done editing then we'd call fontbitmapIO(true) to import the fancy font from the png file back into the font cache that is used by torque.

The first time you import you want the weight to be same as when you imported (in the example above it is 3). But when you do the first import then the weight will be built into the cache so if you go back and edit the png some more and then import again you will want your weight to be 0 or the chars will get off and look like garbage.

I haven't look at this recently and was using an earlier version of TGB so hopefully none of the function names has changed in the most recent version.

Hope this helps.
#10
07/03/2006 (8:01 pm)
OK thanks Kevin, I got it working now. I was thinking it was more complicated. I think the key concept is understanding that once the desired .uft files are written to disk by writeFontCache(); then there is no need for further calls to importCachedFont(), no need for the .png files, no need for the font to be even installed. I thought for some reason that importCachedFont() would have to be called at game's runtime but that is not the case. Thanks again for the demo script. Alex
#11
07/09/2006 (8:54 pm)
Quote:
The first time you import you want the weight to be same as when you imported (in the example above it is 3). But when you do the first import then the weight will be built into the cache so if you go back and edit the png some more and then import again you will want your weight to be 0 or the chars will get off and look like garbage.

make the
%weight = 0;
when I import the edited text png??
#12
07/09/2006 (9:03 pm)
I recommend using Kevin's utility functions, and avoid doing multiple iterations at editing the .png it will just get too confusing.
#13
07/09/2006 (9:42 pm)
Quote:
I recommend using Kevin's utility functions, and avoid doing multiple iterations at editing the .png it will just get too confusing.

i am really confuse about using this function

could you tell me the step of using this.

my step ;
1. populateFonts();

2. fontbitmapIO(false);
it generate the png . right?

3 . then I close the game engine and edit the png.

4. open the game again and use fontbitmapIO(true)
it generate the .uft right ?
but its size is 1k . I think it do not import correctly.


could you help me...............><
#14
07/09/2006 (9:50 pm)
From memory, but you WILL have to experiment

1. look in common/data/fonts and review the .uft files. Delete MyFont*.uft from cache
2. Run TGB
3. populateFonts("MyFont",);
4. fontbitmapIO("MyFont", "12 14 36", false); // exports .png
5. edit png file in ./common/ui/cache/pngs but don't quit out of TGB!
6. fontbitmapIO("MyFont", "12 14 36", true); // imports .png
7. look in common/data/fonts and see the updated .uft files
8. Next time you launch your game, TGB will use the cached font from common/data/fonts

edit:
3. populateFonts("MyFont", "12 14 36"); // or whatever
#15
07/09/2006 (10:05 pm)
I can quit the game engine after

6. fontbitmapIO("MyFont", "12 14 36", true); // imports .png

??
#16
07/09/2006 (10:07 pm)
Yep, because the function calls writeFontCache() which is what writes the .uft files to disk. After your png is imported and written to disk, you don't need to call any of these functions again- Torque just "works" with the font cache. It's a really cool system once you understand it :-)
#17
07/10/2006 (1:11 am)
I have got a new problem..............

the character in png generate is different every time if I export the exisit font. Like Arial.

then I need to open the engine till I finish the artwork of the new font???

I export the Arial as I found that when I export my own font type ,
the png of the font size of 20, 24 , will be a black color.
and the png of other font size , 18, 28, 32, 36 is exported normally.
#18
07/11/2006 (2:52 am)
Hey

can we edit the size of the character in the character strip????

As it will change the dimension of the png image strip.
#19
07/11/2006 (5:40 am)
Ahh, I always wanted to get round to doing this. Looks like someone beat me to it.

Tim Kin Chu: I would guess that you shouldnt edit the character size. If you want to edit the size, then change the weight value (as Kevin explained above) which increases the space around the letters to allow for some editing (drop shadow, outline whatever).

I wonder if this works in TSE/TGB too?
#20
07/11/2006 (8:20 am)
@Phil yep it's part of the torque core so it would definitely work work in TGB etc :-)
Page «Previous 1 2