Game Development Community

T2D Bitmap Fonts Resource Available

by Matthew "Ashteth" Kee · in Torque Game Builder · 08/16/2005 (3:55 pm) · 31 replies

I submitted a resource for T2D bitmap fonts based on NeHe Tutorial 17. Let me know if you have any problems / suggestions. Enjoy :)

T2D Bitmap Fonts
Page «Previous 1 2
#1
08/16/2005 (8:36 pm)
What problem with the TGE font rendering facility is this resource intended to solve? Or, put another way, when should one use your code instead of the TGE font rendering code?
#2
08/16/2005 (8:47 pm)
Quote:Or, put another way, when should one use your code instead of the TGE font rendering code?

You should use this resource when:
You want to rotate your font (the current T2D font resource does not correctly implement this).
You want a pre-rendered font effect (Adobe Photoshop styles come to mind).
#3
08/16/2005 (9:01 pm)
Also, TGE's fonts don't scale with resolution changes. I'm assuming this does.
#4
09/28/2005 (5:45 pm)
Thanks Matthew that's a great resource. LMNOPC Bitmap Font Builder looks great as well. I posted this question on the resource page also:

Do you have a version of this resource that compiles with T2D 1.0.2? I noticed you are usingthe new (T2D 1.1?) t2d* names instead of fx*2D names. It looks like it will be a fair amount of editing to get it to compile with T2D 1.0.2.
#5
09/28/2005 (6:30 pm)
@Alex: Well, you posed the question in two places, so I'll answer in two places ;) I believe that this version will compile with T2D 1.0.2. All the classes I write use the t2d* naming scheme in anticipation of the change (to minimize changes in the future), but the classes are all derived from fxSceneObject2D so they should work with 1.0.2. This also holds true for the latest primitive drawing resource. It is possible that I uploaded an incorrect version of the resource, though at first glance, this does not appear to be the case. In any event, if you have any errors compiling, let me know and I'll provide an update.
#6
09/28/2005 (6:46 pm)
OK I'm using GCC 3.4.2 (MinGW) - maybe that is the problem?

here's the readme, edited to have the 1.0.2 filenames, asis the procedure I followed

Quote:
///////////////////////////////////////////////////////////////////
// Installation Procedure:
///////////////////////////////////////////////////////////////////

Extract the files:
t2dImageFont.cc
t2dImageFont.h
t2dImageFontString.cc
t2dImageFontString.h

to your "Torque2D/SDK/engine/T2D" directory.

Edit the makefile in "Torque2D/SDK/engine/targets.torque.mk"

Under the "SOURCE.T2D=\" group, add this:
" T2D/t2dImageFont.cc \"
" T2D/t2dImageFontString.cc"

Somewhere after line 53 in fxBaseDatablock2D.h
replace two ID_UNUSED_0XX entries with:
"ID_t2dImageFontDatablock"
"ID_t2dImageFontStringDatablock"


In fxImageMapDatablock2D.h,
After line (81) "TextureHandle getImageMapTexture(void);"
Add this:
"U32 getGLBmpID(void);"

At the end of fxImageMapDatablock2D.cc, add this function:
// -----------------------------------------------------------------------------
// Get openGL bmp texture ID used by image.
// -----------------------------------------------------------------------------
U32 t2dImageMapDatablock::getGLBmpID(void)
{
// Return Texture Handle.
return mImageMapTextureHandle.getGLName();
}

Compile...

T2D/fxImageMapDatablock2D.cc:619: error: 't2dImageMapDatablock' has not been declared
T2D/fxImageMapDatablock2D.cc: In function 'U32 getGLBmpID()':
T2D/fxImageMapDatablock2D.cc:622: error: 'mImageMapTextureHandle' undeclared (first use this function)
T2D/fxImageMapDatablock2D.cc:622: error: (Each undeclared identifier is reported only once for each function it appears in.)
make[1]: *** [out.GCC3.RELEASE/T2D/fxImageMapDatablock2D.obj] Error 1
make: *** [default] Error 2

OK so change that method signature to be

U32 fxImageMapDatablock2D::getGLBmpID(void)

and recompile ...
#7
09/28/2005 (6:47 pm)
--> Compiling T2D/t2dImageFont.cc
T2D/t2dImageFont.cc:7:21: dgl/glu.h: No such file or directory
In file included from T2D/./././fxSceneGraph2D.h:22,
                 from T2D/././fxSceneObject2D.h:10,
                 from T2D/./t2dImageFont.h:10,
                 from T2D/t2dImageFont.cc:10:
T2D/./././fxVector2D.h:82:25: warning: no newline at end of file
In file included from ./gui/guiControl.h:28,
                 from T2D/./././fxSceneWindow2D.h:10,
                 from T2D/././fxSceneObject2D.h:26,
                 from T2D/./t2dImageFont.h:10,
                 from T2D/t2dImageFont.cc:10:
./platform/event.h:137: warning: invalid access to non-static data member 'PacketReceiveEvent::data' of NULL object
./platform/event.h:137: warning: (perhaps the 'offsetof' macro was used incorrectly)
./platform/event.h:140: warning: invalid access to non-static data member 'ConnectedReceiveEvent::data' of NULL object
./platform/event.h:140: warning: (perhaps the 'offsetof' macro was used incorrectly)
./platform/event.h:143: warning: invalid access to non-static data member 'ConsoleEvent::data' of NULL object
./platform/event.h:143: warning: (perhaps the 'offsetof' macro was used incorrectly)
In file included from T2D/t2dImageFont.cc:10:
T2D/./t2dImageFont.h:14:36: ./t2dImageMapDatablock.h: No such file or directory
In file included from T2D/t2dImageFont.cc:10:
T2D/./t2dImageFont.h:54: warning: ISO C++ forbids declaration of 'DECLARE_T2DDATABLOCK' with no type
T2D/t2dImageFont.cc: In constructor 't2dImageFontDatablock::t2dImageFontDatablock()':
T2D/t2dImageFont.cc:19: error: class 't2dImageFontDatablock' does not have any field named 'INITIALISE_T2DDATABLOCK'
T2D/t2dImageFont.cc: In static member function 'static void t2dImageFontDatablock::initPersistFields()':

...
#8
09/28/2005 (6:47 pm)
T2D/t2dImageFont.cc:45: warning: invalid access to non-static data member 't2dImageFontDatablock::mImageMapName' of NULL object
T2D/t2dImageFont.cc:45: warning: (perhaps the 'offsetof' macro was used incorrectly)
T2D/t2dImageFont.cc:47: warning: invalid access to non-static data member 't2dImageFontDatablock::mGlyphWidth' of NULL object
T2D/t2dImageFont.cc:47: warning: (perhaps the 'offsetof' macro was used incorrectly)
T2D/t2dImageFont.cc:49: warning: invalid access to non-static data member 't2dImageFontDatablock::mGlyphHeight' of NULL object
T2D/t2dImageFont.cc:49: warning: (perhaps the 'offsetof' macro was used incorrectly)
T2D/t2dImageFont.cc:51: warning: invalid access to non-static data member 't2dImageFontDatablock::mDisplayListBase' of NULL object
T2D/t2dImageFont.cc:51: warning: (perhaps the 'offsetof' macro was used incorrectly)
T2D/t2dImageFont.cc:59: warning: invalid access to non-static data member 't2dImageFontDatablock::mSpace' of NULL object
T2D/t2dImageFont.cc:59: warning: (perhaps the 'offsetof' macro was used incorrectly)
T2D/t2dImageFont.cc:59: error: 'iLoopX' cannot appear in a constant-expression
T2D/t2dImageFont.cc: In member function 'U32 t2dImageFontDatablock::getGLBmpID()':
T2D/t2dImageFont.cc:185: error: 't2dImageMapDatablock' undeclared (first use this function)
T2D/t2dImageFont.cc:185: error: (Each undeclared identifier is reported only once for each function it appears in.)
T2D/t2dImageFont.cc:185: error: 'pImageMapDataBlock' undeclared (first use this function)
T2D/t2dImageFont.cc:185: error: 't2dImageMapDatablock' has not been declared
T2D/t2dImageFont.cc:185: error: expected '>' before '*' token
T2D/t2dImageFont.cc:185: error: expected '(' before '*' token
T2D/t2dImageFont.cc:185: error: expected primary-expression before '>' token
T2D/t2dImageFont.cc:185: error: expected ')' before ';' token
T2D/t2dImageFont.cc:188: error: 't2dBaseDatablock' has not been declared
T2D/t2dImageFont.cc:188: error: 'ID_t2dImageMapDatablock' undeclared (first use this function)
T2D/t2dImageFont.cc:188: error: 'checkT2DDatablock' undeclared (first use this function)
make[1]: *** [out.GCC3.RELEASE/T2D/t2dImageFont.obj] Error 1
make: *** [default] Error 2
vsbuild: Program returned 2

Sorry for including all the warnings from GCC- but I'm not sure which ones are relevant in addition to the errors.
#9
09/28/2005 (9:13 pm)
My apologies, you are in fact correct. The version that was previously up for download did in fact not compile on 1.0.2. I have uploaded a new version. Please try it and let me know if you have any problems.

Thanks for bringing this to my attention :)

T2D Bitmap Fonts
#10
09/28/2005 (9:26 pm)
Thanks Matthew- unfortunately I still can't get it to compile

T2D/t2dImageFont.cc:7:21: dgl/glu.h: No such file or directory

I don't have a glu.h in my SDK at all actually.

T2D/t2dImageFont.cc:59: warning: invalid access to non-static data member 't2dImageFontDatablock::mSpace' of NULL object
T2D/t2dImageFont.cc:59: warning: (perhaps the 'offsetof' macro was used incorrectly)
T2D/t2dImageFont.cc:59: error: 'iLoopX' cannot appear in a constant-expression
#11
09/28/2005 (10:13 pm)
Are there any dependencies from the NeHe tutorial maybe?
#12
09/29/2005 (11:04 am)
That's fairly easy to fix, comment out the gl/glu.h includes... Ok, thats done. The reason why they were there in the first place is that I was thinking of allowing the text to have a rounded rect for a background and later thought that that was too complex and perhaps not even desirable. I didn't catch this error because the version of 1.0.2 I am using for testing also has my latest primitive updates installed which includes glu. In any event, the latest download should work.

Edit: the second error I cannot reproduce on my version of GCC, but I'll try to address it.
#13
09/29/2005 (11:31 am)
Alright, I cannot see a simple fix for the second problem. In MinGW / GCC 3.2, this does not occur. What that line does is add the spacing variables to the data block. If all your charactors are the same size, you could in fact comment it out and the resource will work without it. I know this isn't the best solution, so I'll probably ask a question in the C++ forums and see if anyone knows how to use fixed size arrays in datablocks in a way that it is compatible with the latest version of GCC.
#14
09/29/2005 (8:11 pm)
@Matthew, you say it compiles with GCC 3.2? I am going to revert to that version of GCC and try this again. Here is the macro that's causing the error

T2D/t2dImageFont.cc:59: error: 'iLoopX' cannot appear in a constant-expression

I think that line expands using this macro:

// [ in event.h ]
/// Calculates the location in memory of a given member x of class cls from the
/// start of the class.
#ifndef Offset
#if defined(TORQUE_COMPILER_GCC) && (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
#define Offset(m,T) ((int)(&((T *)1)->m) - 1)
#else
#define Offset(x, cls) ((dsize_t)((const char *)&(((cls *)0)->x)-(const char *)0))
#endif
#endif

That's the kind of C code I HATE trying to understand. It's gnarly and nasty.
#15
09/29/2005 (8:19 pm)
Then there is types.h defining various Offsets() also.
#16
09/29/2005 (8:43 pm)
It compiles with MinGW gcc 3.3.1 !!!
#17
09/29/2005 (9:12 pm)
But example doesn't run. I get this error

Quote:Unable to instantiate non-conobject class t2dImageMapDatablock.

from this line of script

datablock t2dImageMapDatablock(BMP_font_monaco)
	{
	   mode = cell;
	   cellWidth = 32;
	   cellHeight = 32;
	   textureName = "~/client/images/BMP_font_monaco.png";
	};

then lots of this

Quote:
T2D Engine initialized...
t2dImageFontDatablock::getGLBmpID() - t2dImageMapDatablock Datablock is invalid! (BMP_font_monaco)
t2dImageFontDatablock::getGLBmpID() - t2dImageMapDatablock Datablock is invalid! (BMP_font_monaco)
t2dImageFontDatablock::getGLBmpID() - t2dImageMapDatablock Datablock is invalid! (BMP_font_monaco)
[repeats]
#18
09/30/2005 (4:11 pm)
This is another error resulting from the upcoming name changes. "t2dImageMapDatablock" should be "fxImageMapDatablock2D". The resource has been updated (again). Anything else you can think of to make this simple "fix" go wrong ;) You got me to test both the "script" and the C++ files this time, so I think everything should work (I got the font to appear at least). I still don't know what is causing the GCC 3.4 error though.

Hopefully GG can release the new T2D version soon and we can stop playing these name games... As you can see, these simple "fixes" aren't always so simple. In any event, I'm glad I changed all the names when I did. With as much code as I've written, it would have been a real pain to migrate in the future. I'm sitting on at least 1 more resource which should be of interest to people, that I think I'm just going to avoid releasing for now for this reason...
#19
09/30/2005 (5:27 pm)
@Matthew, OK success at last! Thanks for all your hard work putting together this resource. Couple of suggestions about the script because I thought it was not working

// Set the blend colour of the text.
%text.setBlendColour("255 255 255 192");

That's going to render invisible because many users will be starting out with a white background in their T2D mod. Maybe 50 50 50 255 instead for the example?

// Change the scale the text is displayed at.
%text.setScale("0.8");

0.8 scale was causing it to render in a microscopic area; but I am running a non-standard camera size/position which is probably the reason. Bumping the scale up to 10 caused it to be easily viewable for me.

Next to try a wierd font... I'll post a screenshot if I get the character spacing and everyhing figured out . :-)
#20
09/30/2005 (5:38 pm)
@Matthew, OK here a roadblock for me- character spacing

// Set the spacing of charactor 0 to 14 in pixel coordinates.
   // You will want to do this for charactors 0 ~ 127 if your
   // font is not a monospace font.
   //space_0 = 1.36719;
   //space_1 = 1.36719;

That format does not seem to be any of the available 3 formats in File > Save Font Widths in Bitmap Font Builder. How did you come up with the pixel coordinates, down to fractions of pixels?

Here is a font I was playing around with (Asimov) that clearly needs it's spacing adjusted:

mindlube.com/garagegames-forum/bmpfont-asimov.png
Page «Previous 1 2