T2D Text Display Class - Updated
by Mark Mesich · 04/11/2006 (2:02 pm) · 26 comments
Download Code File
The following modification have been made to the original posting:
- Class names, file names, method calls etc. have been updated to fit with the latest naming conventions and account for the new names of the supporting objects.
- Melv May's coding suggestion has been incorporated to remove the need to add the method to t2dSceneWindow.h (previously fxSceneWindow2D.h) as mentioned in the original article.
In light of these changes the sample script might look like the following:
The following modification have been made to the original posting:
- Class names, file names, method calls etc. have been updated to fit with the latest naming conventions and account for the new names of the supporting objects.
- Melv May's coding suggestion has been incorporated to remove the need to add the method to t2dSceneWindow.h (previously fxSceneWindow2D.h) as mentioned in the original article.
In light of these changes the sample script might look like the following:
$test = new t2dTextObject() { scenegraph = sceneWindow2D.getSceneGraph(); };
$test.setText("Test String");
// default font is Lucida Console, 14pt
$test.setFont("Tahoma");
$test.setSize(24);
// default font color is 0 0 0 255 (full black)
$test.setFontColor("255 255 255 255");
$test.setPosition("10 10");
$test.setLinearVelocityX(2);
// set the alpha of these to 0 to disable them (they won't draw for a slight speedup)
// they are disabled by default
$test.setBorderColor("0 0 255 255"); // R/G/B/A
$test.setBannerColor("255 0 0 255"); // R/G/B/A
#2
04/15/2006 (10:37 am)
When I use the snippet above$test = new t2dTextObject() { scenegraph = sceneWindow2D.getSceneGraph(); };I get a crash w/ unhandled exception here in t2dscenegraph.ht2dSceneWindow* getCurrentRenderWindow( void ) { return mpCurrentRenderWindow; };However if I reference a particular scenegraph then it works fine:$test = new t2dTextObject() { scenegraph = fishSceneGraph2D; };Any ideas about that?
#3
Are you running with the latest engine source? The script above is was taken from my game and works without issues. In fact I use it in several places.
If you are still having trouble, I would love to try to help you out further.
04/26/2006 (11:02 am)
Sorry for the delay Alex. I didnt realize that the posting was approved.Are you running with the latest engine source? The script above is was taken from my game and works without issues. In fact I use it in several places.
If you are still having trouble, I would love to try to help you out further.
#4
04/26/2006 (2:47 pm)
Hi Mark - no worries since I can get it to work by naming a specific scenegraph it's not a big deal. Probably something weird with the new Project/Level management stuff in beta2. Thanks
#5
04/27/2006 (7:15 pm)
Definitely weird - because I am running the latest as well. If you have a sample script you would like me to try, or if I can help out in another way then please let me know.
#6
05/17/2006 (10:36 am)
...sorry, nevermind...
#7
@alex - didn't require naming the scenegraph either for me in RC2 ... wooot!
06/14/2006 (10:31 am)
Worked for me right out of the box in RC2.. SWEET RESOURCE! @alex - didn't require naming the scenegraph either for me in RC2 ... wooot!
#8
06/14/2006 (1:24 pm)
Hey Rodney - Glad you found it useful!
#9
-Garrett
06/26/2006 (5:45 pm)
Wow, this is really awesome. I would like to point out one thing I've encountered: I have my game broken down into two different t2dSceneWindows. Starting from the left and moving right, the first one has an extent of 100X480 and the other is 540X480. What happens is that on the bigger one, text seems to clip itself 100 units short of the right side. I've looked into the source to try and fix it, but I can't wrap my head around it. Excellent resource regardless.-Garrett
#10
-G
07/01/2006 (9:34 am)
Well, it seems I got the above problem to go away by making a small modification to t2dTextObject.cc around line 243. I changed the following:// shift scale/viewport size glPushMatrix(); dglSetViewport(RectI(0,0, updateRect.extent.x, updateRect.extent.y)); glScalef(cameraScale.x,cameraScale.y,0); // scale the text to the current camera scale glTranslatef(updateRect.point.x, updateRect.point.y,0); dglDrawText( mpFont, Point2I(objectLoc.mX+mStringFontSize.x/-2,objectLoc.mY+mStringFontSize.y/-2), mTextString , NULL );to this:
// shift scale/viewport size glPushMatrix(); dglSetViewport(RectI(window->mBounds.point.x,window->mBounds.point.y, updateRect.extent.x, updateRect.extent.y)); glScalef(cameraScale.x,cameraScale.y,0); // scale the text to the current camera scale glTranslatef(updateRect.point.x - window->mBounds.point.x, updateRect.point.y -window->mBounds.point.y,0); dglDrawText( mpFont, Point2I(objectLoc.mX+mStringFontSize.x/-2,objectLoc.mY+mStringFontSize.y/-2), mTextString , NULL );So if you have problems with multiple t2dSceneWindows and this resource, try this.
-G
#11
07/02/2006 (4:15 pm)
Cool! Thanks for the update Garret. Sorry going silent on you - I was away for a little while. Glad to hear you got things sorted out.
#12
07/03/2006 (8:16 pm)
Apologies for my ignorance, but where do I put these files, and how do I get Torque to access the information contained therein so that I can call a new t2dTextObject?
#13
1. unzip the resource and move the 2 files (.cc and .h) into engine\source\T2D
2. add the .cc and .h files to your compiler's project and recompile TGB.exe
3. run TGB.exe and instantiate t2dtextobjects as shown in the example torquescript
Hope this helps
07/03/2006 (8:28 pm)
@David, here is how to do it:1. unzip the resource and move the 2 files (.cc and .h) into engine\source\T2D
2. add the .cc and .h files to your compiler's project and recompile TGB.exe
3. run TGB.exe and instantiate t2dtextobjects as shown in the example torquescript
Hope this helps
#14
Sorry...pretty clueless here, lol...
07/03/2006 (8:46 pm)
@Alex, thanks for the quick response. It's step 2 that has got me stumped. Which folder would that be in? I've got the files in the T2D directory of the engine source code, and have used the example torque script. For example, my project is called Marbled...so would that be in Marbled\managed, for example? And how do I recompile TGB.exe? Just run it?Sorry...pretty clueless here, lol...
#15
07/03/2006 (8:50 pm)
David, no problem. To recompile TGB.exe you first need a version of TGB with source code (assuming you have that). Take a look in the folder engine\compilers and you will see the project files for make (GCC/command line compilation) for Visual Studio on Windows, and for Xcode on Mac OS X. The answer depends on which compiler and platform you are working on.
#16
I get a single warning during this process, regarding the header file: warning C4301: 't2dTextObject::integrateObject': overriding virtual function only differs from 't2dSceneObject::integrateObject' by const/volatile qualifier.
And then, when I close the compiler and open TGB.exe, I get this warning when I try to use the example torquescript: Unable to instantiate non-conobject class t2dTextObject.
Any ideas as to what I'm doing wrong, here?
07/03/2006 (10:38 pm)
Okay, I'm not sure what I'm doing wrong. I'm using Visual Studio 2005 as my compiler. I go into the Torque Game Builder\engine\compilers\VisualStudio 2005 folder and opening the project titled 'T2D'. I add t2dtextobject.cc and t2dtextobject.h to the project in the Source Files/T2D directory. Then I click on 'Rebuild T2D' under the 'Build' menu.I get a single warning during this process, regarding the header file: warning C4301: 't2dTextObject::integrateObject': overriding virtual function only differs from 't2dSceneObject::integrateObject' by const/volatile qualifier.
And then, when I close the compiler and open TGB.exe, I get this warning when I try to use the example torquescript: Unable to instantiate non-conobject class t2dTextObject.
Any ideas as to what I'm doing wrong, here?
#17
07/03/2006 (10:49 pm)
Not sure, but a warning is not preventing the build from completing. I get warnings with VS .Net as well. An error will halt the build, but warnings are typical. Try opening the .sln (Solution) file then doing Build > Solution
#18
07/03/2006 (10:53 pm)
Also the warning about "Unable to instantiate non-conobject class" just means that the t2dTextObject class was not compiled into TGB.exe.
#19
07/20/2006 (6:48 pm)
No, I just tried this all over again and I still can't figure it out. The build seems to go fine - am I supposed to include the file somewhere in one of my .cs files?
#20
What errors are you getting now? Did you follow the instruction Alex posted above? Which version of TGB are you using?
Hopefully we can get you sorted out.
Thanks,
Mark
07/20/2006 (7:49 pm)
Hey David, What errors are you getting now? Did you follow the instruction Alex posted above? Which version of TGB are you using?
Hopefully we can get you sorted out.
Thanks,
Mark

Torque Owner Alex Rice
Default Studio Name