Game Development Community

Image Font related Import/exportCachedFont() problem

by Playware · in Torque Game Builder · 08/29/2008 (12:44 am) · 4 replies

Hi All,

I was trying to use bitmap fonts for my game. For this I used code suggested shown on this forum. I want to use bipmap font in to guiTextCtrl or guiListBoxCtrl or even in t2dTextObject . I used importCachedFont() and exportCachedFont(). As result, in guiTextCtrl output is some garbage text.

My code is something like this......................


function populateFonts( %font, %sizes)
{
for (%i = 0; %i < getWordCount(%sizes); %i++) populateFontCacheRange(%font, getWord(%sizes, %i),
32, 126);
writeFontCache();
}


function fontbitmapIO( %font, %sizes, %import){
if ( %font $= "") return;
%pngdir = "pngs/";
%fontdir = "C:/myGameDirectory/common/data/fonts/";

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

%weight = 2; // Edit this if you need more space between fonts

%fileName = %fontdir @ %pngdir @ %font SPC %size @ ".png";

if (%import)
importCachedFont(%font, %size, %fileName, %weight, 0);
else
exportCachedFont(%font, %size, %fileName, %weight, 0);
}
writeFontCache();
}


function fontboy_selected(%font, %size)
{

if (%size $= "") return;

$fontboy_font = %font;
$fontboy_sizes = %size;

populateFonts( $fontboy_font, $fontboy_sizes );
fontbitmapIO( $fontboy_font, $fontboy_sizes , false );
}


Now my step was....

1). I called fontboy_selected("Arial", 24);
2). I got Arial 24.png file into my directory/pngs folder
3). I kept my game running.
4). I edited .png file into photoshop and saved in same place
5). I called fontbitmapIO("Arial", 24, 1) to import png file into font.
6). I set guiTextCtrl.text = "Testing Text";


my Observations.....................

1). guiTextCtrl displays something garbage like (;'"v'!) insted of "Testing Text";
2). In photoshop, I changed the png color from white to red , but here in guiTextCtrl displays black png font.






what could be the problem?




a). Is there any specific format to save png file in photoshop after making modification (I saved into RGB
format)
b). Can we use this image font into guiTextCtrl or other gui control to display text. If "yes" then how we have
to define gui profile to support this.

c). Can we use this image font into t2dTextObject also. If "Yes" then how we will define that.


If any idea, please help me...





thnaks a lot.

#1
08/29/2008 (4:02 pm)
When I used FontBoy I used it to create the font AND to import it into TGB and it worked fine. I don't really know what goes on behind the scenes, but it looks to me like you're trying to do the same thing two different ways, or use FontBoy for part of it and script for another part. For all I know this could be perfectly legitimate!

Try keeping your populateFonts function and copy away and remove the other functions you've got here (copy away just in case this doesn't work). Then from your game/main.cs call
populateFonts("Arial", "24");

Then just use Arial 24 in your GUI items.

No need to use calls to FontBoy, and comment out the populateFonts bit afterwards 'cause you don't want it to run when the game is distributed.
#2
08/29/2008 (4:04 pm)
Oh - and

Quote:
%fontdir = "C:/myGameDirectory/common/data/fonts/";

Yucky! Don't hardcode paths - you have no idea where your players are going to install your game, and that folder may well not exist when they're playing it.
#3
09/04/2008 (2:00 am)
Hi Shaz,

Can you use this font in Gui also like GuiTextCtrl, GuiEditTextCtrl and etc. If Yes, then how you are definig gui profile for these?

thanks.
#4
09/04/2008 (2:30 am)
I am creating my gui via script, not with the Gui editor, but yes, I have GUITextCtrl, etc. I believe as long as your profiles are defined in game/gameScripts/guiProfiles.cs they will be picked up by the TGB editor and you can use them in the GUI Editor. I made a post a week or two ago for an issue I was having and there were some useful explanations given.