Game Development Community

Working with text objects in Editor

by Drew -Gaiiden- Sikora · in Torque Game Builder · 12/05/2006 (11:49 am) · 22 replies

I think I'm using the t2dTextObject wrong or something - when I create it in the editor it shows up all blocky, and when I run the level and use addAutoFontSize to size it properly I get bleed-through withe the various characters and it looks like this

members.gamedev.net/gaiiden/images/screens/bb/bleed.jpg
I would have thought the implementation of fonts would be a bit more streamlined - how come you can't choose a font size in the level editor??
Page «Previous 1 2
#1
12/05/2006 (11:57 am)
It should work fine if you build it in the levelbuilder (it might not work if you create it but don't type anything in. If it's not showing up correctly, then you didn't add the font size correctly. I believe it was done this way because a vector font renderer wasn't going to happen for the first release of the textObject. Anyway, I add auto font sizes like this:
%camArea = sceneWindow2D.getCurrentCameraArea();
%camHeight = mAbs( getWord( %camArea, 1) - getWord( %camArea, 3) );
%pixelHeight = getWord( sceneWindow2D.getWindowExtents(), 3);
%this.textObj.addAutoFontSize( %pixelHeight , %camHeight, %fontSize);

You might have been sending in the wrong values for one of the heights. I was having the same problems until I found out what the three parameters really are. It should generate your sizes just fine this way.

EDIT: Forgot to mention this - %fontsize in the code above is the lineHeight you want.
#2
12/05/2006 (5:31 pm)
Thanks Tom, I'll give your code a try.

About the font creation - yea I would click and drag a t2dText object from the editor sidebar onto the game level and it would show up all horribly pixelated, like the font size was 1 or something. Here's what it looks like in the editor for me

members.gamedev.net/gaiiden/images/screens/bb/text.jpg
Kinda disappointing if you can't get it to display properly in the level builder without using some code - or am I missing a step somewhere??
#3
12/05/2006 (6:08 pm)
It's still kinda wonky. Drag it in and immediately start typing. If you resize it or do something else first, it will use a font size of 1 or something.

Also, your GUI looks awesome!
#4
12/06/2006 (10:59 am)
Yeaa... that didn't work so well either. I dragged the object onto the screen, immediately typed and got this

members.gamedev.net/gaiiden/images/screens/bb/txt.jpg
Maybe it has something to do with my camera size (1024x768) and design resolution (also 1024x768)??
#5
12/06/2006 (11:26 am)
Hmmm. Have you tried adding a font size with the code above onLevelLoaded to the object?

It works fine at the resolutions I've tried. See if autogenerating the fontsize works.
#6
12/06/2006 (6:12 pm)
Tom, my whole point here is that this is the level builder. I don't see why I should have to use any code in order to get my fonts to display properly!

I still haven't had a chance to test the code, but I'll be using it seeing as I don't have any other option it seems...
#7
12/06/2006 (7:13 pm)
I totally agree with you that it should work, but it'll help figure out where the problem is if you try out the code. If it works when autogenerating, the problem is in the levelbuilder tool, but if it doesn't work then either, the problem lies in the textObject itself.

Random other ideas that might result in your problem:
>Arial/Whatever font either isn't on your computer or it's not being found correctly by TGB
>The textObject doesn't work on your computer for some reason (what are your specs? - which OS are you running?)
>Did you by any chance have a previous version of the textObject and only replace that project's exe or something? I know an early version of the textObject had the problems you're experiencing.

Hope that leads to a solution.
#8
12/07/2006 (12:21 am)
Well, I placed the code you gave me in the game.cs file so that it would run when the level is loaded. I used 31 for my font size, since that was the height of my text object (for the record, I tried others. Higher sizes looked like the image below, when I tried 10 the text was so pixelated it was near unreadable). This is what I got.

members.gamedev.net/gaiiden/images/screens/bb/bleed2.jpg
Quote:
Arial/Whatever font either isn't on your computer or it's not being found correctly by TGB
Changing the font doesn't help one bit - they all end up looking horrible

Quote:
The textObject doesn't work on your computer for some reason (what are your specs? - which OS are you running?)
WinXp Pro SP2, Core 2 Duo E6600, 2GB RAM, ATI x1900GT

Quote:
Did you by any chance have a previous version of the textObject and only replace that project's exe or something? I know an early version of the textObject had the problems you're experiencing.
Nope, this is a clean install of TGB 1.1.3 on this machine

I did some more experimenting, loaded some texts into the default TGB project to make sure I hadn't screwed up some project setting or something. Still looked the same as the shot above - clean but with some bleeding of other characters showing through still. I also notice some weird rotational effects:

members.gamedev.net/gaiiden/images/screens/bb/bad_text.jpgmembers.gamedev.net/gaiiden/images/screens/bb/bad_text2.jpg
Still fiddling...
#9
12/07/2006 (11:14 pm)
Blah. So here's what my font looks like creating it in the code rather than the editor

members.gamedev.net/gaiiden/images/screens/bb/nogo.jpg
Still has some bleed-through visible. This is the code I used to generate the text

%camArea = winGameDifficulty.getCurrentCameraArea();
%camHeight = mAbs( getWord( %camArea, 1) - getWord( %camArea, 3) );
%pixelHeight = getWord( winGameDifficulty.getWindowExtents(), 3);

$music = new t2dTextObject()  
{ 
   scenegraph   = guiSceneGraph;
   font         = "BLADEEDGE HELIROUND";
   text         = TorqueDB.getData("game music", $gameMusic, $TEXT_FIELD);
   textAlign    = "Center";
   BlendColor   = "1 1 0 1";
   textColor    = "1 1 0 1"; 
   autoSize     = "1"; 
   lineHeight   = "37"; 
   aspectRatio  = "1"; 
   fontSizes    = "36";
};

$music.addAutoFontSize(%pixelHeight, %camHeight, 37);
$music.text = TorqueDB.getData("game music", $gameMusic, $TEXT_FIELD);
$music.setPosition(0, 50);

Someone let me know if I'm missing something or doing anything wrong, since I don't hear other people chiming in saying their text objects come out looking messed up as well.

It's confusing to me why this implementation of text objects is more of a pain than this one, which I used without a problem - almost makes me want to install C++ Express and compile it back in...
#10
12/10/2006 (1:12 pm)
Hey can anyone at least assure me that I'm not the only one with this problem?
#11
12/10/2006 (4:55 pm)
I'm also having this problem when creating TextObjects inside the editor.
#12
12/10/2006 (5:54 pm)
Good to know, I was afraid it was just me being stupid somehow
#13
12/11/2006 (12:32 pm)
I was working on some stuff with textObjects again, and I think there might be something weird going on when you have more than one fontSize - if you still have that code generating fontsizes, try
$music.removeAllFontSizes();
. Put that right before you call addAutoFontSize. It cleared up the fonts a bit for me in some cases.
#14
12/13/2006 (4:56 pm)
I have this problem too.
Is this not a question of Texel ? Pixel present inside the texture aren't enough or correctly standing.
I did not see any informations about the new text tool so maybe it need improvement. I remember an engine where you'll have to put the quadpoly in another blending mode so alpha show up and this improve the quality of rendering as there isn't grabbing no more.
It depend on the font too.

About the rotation problem you just have to uncheck the "hide overflow" option ;)
#15
12/15/2006 (10:16 pm)
Well, other things related to the game and the industry pulled me away from coding for a few days, so I only got a chance to try out your suggestion tonight, Tom. Unfortunately it didn't seem to make a difference for me.

@Rivage - ah, thanks :)
#16
12/16/2006 (10:17 am)
I had some weird stuff going on for a while (and showed them to the TGB team lead) but they magically dissapeared the next time I opened TGB. The levelbuilder might be caching fonts or something - I haven't looked into the source to see where it generates fontsizes at all, so I'm not sure.

The one thing that's really confusing is that it doesn't work for you in the levelbuilder. Hmmm. Next time I'm working with text objects, I'll try to figure it out.
#17
03/04/2007 (11:05 am)
I've found two workarounds that seem to help.

First, I made this change:
*** tools/levelEditor/scripts/levelEditor.ed.cs~	2007-03-04 10:21:11.921047368 -0800
--- tools/levelEditor/scripts/levelEditor.ed.cs	2007-03-04 10:22:10.389158864 -0800
***************
*** 106,111 ****
--- 106,112 ----
  
  function LevelBuilderCreateTool::onTextObjectCreated( %this, %object )
  {
+    %object.removeAllFontSizes();
     %object.hideOverlap = false;
     if( %object.getWidth() > 2.0 )
     {

Secondly (and I only tested this on Linux w/ an unofficial TGB 1.1.3), I found doing the following in the console after changing the "character height" attribute of the object in the level editor helps greatly:
2230.removeAllFontSizes();
2230.addFontSize("128");
where 2230 is the text object created in the editor. Obviously, substitute in the proper object ID. I don't think "128" is magic -- I just think it needs to be a number larger than the effective character height.

Should some piece of code do this automatically, or is this just a hint as to where the weirdness is?
#18
03/09/2007 (3:34 pm)
I have the same problem. Could it be related to the widescreen ratio?
#19
03/10/2007 (1:31 am)
Quote:
Could it be related to the widescreen ratio?
I don't know what you mean, I run my game in 1024x768

@andrew - I think I had that fix mentioned to me before and it didn't work, but I'll try it again when I get a chance (the first one is kinda the same but I know for sure I haven't tried yet)
#20
03/27/2007 (12:00 am)
Something's seriously not working properly.

1) I get really blocky text by default from the editor. If I edit the level files (changing the font sizes) after I quite TGB and restart, they seem okay.

2) I get text that seems to disappear and reappear depending on the current camera. It seems to be related to the artifacting that Drew mentioned (looks similar). Scolling up and down on the mouse in the editor shows some weird stuff. SOLVED: The problem stemmed from trying to use Datablocks within the Editor. Drew? You using Datablocks for your text?

3) I use the following t2dSceneObjectDatablock for initialization within the editor:
// For game text setup.
new t2dSceneObjectDatablock(kanji)
{
	// Generic settings.
	BlendColor = "0 0 0 1";
	BlendingEnabled = "1";
	CollisionActiveReceive = "0";
	CollisionActiveSend = "0";
	CollisionPhysicsReceive = "0";
	CollisionPhysicsSend = "0";
	Layer = "5";
	Size = "10 10";
	
	// t2dTextObject related settings.
	text = "土";
	font = "Karate Medium";
	wordWrap = "0";
	hideOverflow = "0";
	textAlign = "Center";
	lineHeight = "10";
	aspectRatio = "1";
	lineSpacing = "0";
	characterSpacing = "0";
	autoSize = "1";
	fontSizes = "24 32 48 64 128";
};
That makes for some interesting stuff. Each time I reopen the editor, the text gets funkier and funkier. Some function isn't happy with the way things are changing.

Are we not supposed to use datablocks for t2dTextObjects thusly?

(EDIT: It appears that I get the weird artifacts regardless of datablock or not. Though... the datablock info isn't always copied properly...)

I did find that removing all the font sizes and adding one that I hadn't recently added seemed to fix things temporarily. After a few reloads, the fonts would inevitably break and start producing crazy artifacts (generally a chunk of the top and right side of a character simply not appearing [this could be related to the fall-back font mentioned above]).

Is there an 'accepted' way of doing things here? Are t2dTextObject's accessor-less settings incompatible with datablocks in some way?
Page «Previous 1 2