For TGB Pro users: t2dTextobject
by Matthew Langley · in Torque Game Builder · 08/11/2006 (2:43 pm) · 13 replies
Here is the latest version of t2dTextObject and how to use it. It requires adding some files to the source code so you must be a TGB Pro user to add it.
About the author
I Manage Tool Development for Torque at InstantAction
#2
For those who don't know how to include the file to their project, (and are using VC++ 2005 Exp. Ed), open up the T2d SDK project. Then click on the project tab --> Add Existing Item. Add the two files then press F7 to build the solution. Thought that might be useful for people who weren't sure (like me) on how to add files to the project. At first I thought I had to include them using #include in a main C++ file :/.
Thanks again.
edit: lol, just noticed. And thank you Michael :)
08/11/2006 (3:52 pm)
Thanks Matt, very useful stuff! For those who don't know how to include the file to their project, (and are using VC++ 2005 Exp. Ed), open up the T2d SDK project. Then click on the project tab --> Add Existing Item. Add the two files then press F7 to build the solution. Thought that might be useful for people who weren't sure (like me) on how to add files to the project. At first I thought I had to include them using #include in a main C++ file :/.
Thanks again.
edit: lol, just noticed. And thank you Michael :)
#3
I'm unclear on the mipMapping field - what exactly does that do?
08/12/2006 (10:17 am)
W00t - very cool indeed! The uses for this just flood my brain :) Also finally gave me an excuse to try my hand at recompiling the engine. No problems! :)I'm unclear on the mipMapping field - what exactly does that do?
#4
EDIT:
Duh... Thank you...
08/12/2006 (1:46 pm)
This sounds great, I would love to see some screen shots, for those of us who don't own the source....EDIT:
Duh... Thank you...
#5
Very nice by the way, thanks for taking the time to code this Michael. Extra things like this are eventually going to cause me to break down and finally use the source part of my pro license. :) Or because it was done as a bounty, will it make its way into the precompiled binary of 1.1.2?
08/12/2006 (3:52 pm)
There is a screenshot on the TDN page Scott.Very nice by the way, thanks for taking the time to code this Michael. Extra things like this are eventually going to cause me to break down and finally use the source part of my pro license. :) Or because it was done as a bounty, will it make its way into the precompiled binary of 1.1.2?
#6
08/17/2006 (5:20 pm)
Any help with that mipmap field?
#7
So if you have a font like this:
Then there should be font textures for the sizes 10, 55, 100. These are used when the t2dTextObject is scaled. If you've got a t2dTextObject that is 80 pixels high on the screen it will use the 100px texture, if the object is 60 pixels high it will take 55px texture.
With mipMapCount you can control the number of mipmaps because the texture pages of a font can take up quite some memory for large font scales. Without the field specified there will be textures generated every 14px or something. You should be able find the value in t2dFontDatablock::onAdd().
08/17/2006 (10:39 pm)
You can specify how may mipmaps are generated for the font. If you don't do that the object will calculate this automatically.So if you have a font like this:
datablock t2dFontDatablock(someFont)
{
faceName = "Arial";
maxSize = 100;
minSize = 10;
mipMapCount = 3;
};Then there should be font textures for the sizes 10, 55, 100. These are used when the t2dTextObject is scaled. If you've got a t2dTextObject that is 80 pixels high on the screen it will use the 100px texture, if the object is 60 pixels high it will take 55px texture.
With mipMapCount you can control the number of mipmaps because the texture pages of a font can take up quite some memory for large font scales. Without the field specified there will be textures generated every 14px or something. You should be able find the value in t2dFontDatablock::onAdd().
#8
08/18/2006 (12:58 am)
This is awesome, thanks!
#9
08/23/2006 (10:27 pm)
There seems to be a bug in this resource where calling "setText()" before you have set the text will crash the engine. I would think this should fail gracefully by returning an empty or also printing a message to the console.
#10
I'm not sure if the "convertUTF16toUTF8" call is supposed to handle nulls or not so I'm just shunting before the call. This is more of a workaround than a fix.
08/23/2006 (10:58 pm)
I'm getting around the problem by changing getText to look like:const char* t2dTextObject::getText()
{
if (mText == NULL)
{
return "";
}
const U32 len = mTextLength * 3 + 1;
FrameTemp<UTF8> buffer(len);
convertUTF16toUTF8(mText, buffer, len);
return buffer;
}I'm not sure if the "convertUTF16toUTF8" call is supposed to handle nulls or not so I'm just shunting before the call. This is more of a workaround than a fix.
#11
t2dTextObject::getText() should just look like this:
Thanks a lot Ben for reporting this!
08/24/2006 (1:21 am)
Did I write this getText() method? It is pure luck if it works. "buffer" is memory allocated on the frameAllocator and will be deallocated right after the "return". And "mTextLength" does not seem to get initialized in the constructor. It should be zero.t2dTextObject::getText() should just look like this:
const char* t2dTextObject::getText()
{
return mConsoleBuffer ? mConsoleBuffer : "";
}Thanks a lot Ben for reporting this!
#12
08/24/2006 (9:03 am)
That certainly also seems to fix the problem. Is there any problem with eliminating the conversion from UTF16 to UTF8? I'm not really sure why that was there.
#13
08/24/2006 (9:09 am)
The text object stores the text string twice: Once as UTF16 for fast rendering and once in UTF8 for easy console access. I added the UTF8 string later for the persist fields but I must have forgotten to update the getText() method.
Torque Owner Michael Woerister