World-space 3D text ?
by Orion Elenzil · in Torque Game Engine · 06/30/2008 (5:02 pm) · 17 replies
Howdy folks -
i've got a use for some in-world text,
and would like to try adapting the existing 2D text engine to the 3D world.
eg, so i could add a SceneObject to the mission and then set its text and it would render in-world.
MLText3DObj or something.
any words of wisdom out there ?
it seems like it should be doable since the 2D text engine boils down to 3D OpenGL calls which just happen to be in screen space, but of course the difficulty is always in the details.
i searched as well as i could and found this resource: Textured Text & Billboard text, but it doesn't seem to be quite what i'm after. (eg, it seems to be screen-aligned, and requires additional font files)
all i really want to display is a number (a score for an in-world minigame),
so could do a quick-n-dirty thing with a series of DTS quads or similar,
but i'd really like something more generic and reusable.
tia,
orion
i've got a use for some in-world text,
and would like to try adapting the existing 2D text engine to the 3D world.
eg, so i could add a SceneObject to the mission and then set its text and it would render in-world.
MLText3DObj or something.
any words of wisdom out there ?
it seems like it should be doable since the 2D text engine boils down to 3D OpenGL calls which just happen to be in screen space, but of course the difficulty is always in the details.
i searched as well as i could and found this resource: Textured Text & Billboard text, but it doesn't seem to be quite what i'm after. (eg, it seems to be screen-aligned, and requires additional font files)
all i really want to display is a number (a score for an in-world minigame),
so could do a quick-n-dirty thing with a series of DTS quads or similar,
but i'd really like something more generic and reusable.
tia,
orion
About the author
#2
07/07/2008 (8:00 pm)
I would suggest using dts. It won't be as reusable, but it would take MUCH longer to code a 3d text system.
#3
- indeed.
it's just tempting to adapt the existing system.
using DTS or a restricted-alphabet texture solution could be done in a day or so,
but the art-pipeline for that is pretty burdensome.
fwiw, i haven't yet looked into adapting the existing system.
if/when i do i'll post something here.
07/07/2008 (10:27 pm)
Thanks for the reply, Dan.- indeed.
it's just tempting to adapt the existing system.
using DTS or a restricted-alphabet texture solution could be done in a day or so,
but the art-pipeline for that is pretty burdensome.
fwiw, i haven't yet looked into adapting the existing system.
if/when i do i'll post something here.
#4
07/09/2008 (1:09 am)
It might not be any use to you but have you looked at the Gem-a-Day series of resources garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=14896 I know it currently only allows numbers but can't imagine it'd be too hard to tailor to your needs
#5
yes, i understand pretty well how to do something similar to the plastic games resource #7,
but what i'm really hoping to do is avoid the need to bake-in textures of the alphabet.
eg,
not have images like these baked in:

.
fonts are already baked in to the client quasi-dynamically as the *.gft files,
which finally boil down to calls to good old glDrawArrays(GL_QUADS..),
which it seems there's no particular reason those need to be screen-aligned.
anyhow.
it looks like i'm probably not going to look at this for a few weeks,
but i'll post here if anything exciting happens.
thanks again for the reply!
07/09/2008 (9:29 am)
Hey Andy - thanks for the reply.yes, i understand pretty well how to do something similar to the plastic games resource #7,
but what i'm really hoping to do is avoid the need to bake-in textures of the alphabet.
eg,
not have images like these baked in:

.fonts are already baked in to the client quasi-dynamically as the *.gft files,
which finally boil down to calls to good old glDrawArrays(GL_QUADS..),
which it seems there's no particular reason those need to be screen-aligned.
anyhow.
it looks like i'm probably not going to look at this for a few weeks,
but i'll post here if anything exciting happens.
thanks again for the reply!
#6
definitely worked ! ie, the text renders in world-space!

we've encountered three problems so far:
* the text looks pixelated when viewed close-up
- this is fixed either by calling glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) when drawing the text, or by commenting out the calls to setFilterNearest() in gFont.cc().
* the text looks pixelated when viewed from far away
- strangely, not calling setFilterNearest() did not fix this, which is a bit surprising. i would have expected that to cause mipmap generation etc. but it's not a terrible flaw.
* the character quads have some texture bleed-over.
- adding calls to mTextureSheets[i].setClamp(true) in gFont.cc did not fix this. .. which now that i think about it is not surprising at all, since each character is not in fact its own texture. Strangely the edge artifacts are there either with GL_NEAREST or GL_LINEAR. I guess i'll try moving the texture coords in one pixel.
anyway, that's the update. any advice ?
08/17/2008 (11:33 am)
We tried the naive thing and simply set up transform matrices and then called dglDrawText(), and the core of it definitely worked ! ie, the text renders in world-space!

we've encountered three problems so far:
* the text looks pixelated when viewed close-up
- this is fixed either by calling glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) when drawing the text, or by commenting out the calls to setFilterNearest() in gFont.cc().
* the text looks pixelated when viewed from far away
- strangely, not calling setFilterNearest() did not fix this, which is a bit surprising. i would have expected that to cause mipmap generation etc. but it's not a terrible flaw.
* the character quads have some texture bleed-over.
- adding calls to mTextureSheets[i].setClamp(true) in gFont.cc did not fix this. .. which now that i think about it is not surprising at all, since each character is not in fact its own texture. Strangely the edge artifacts are there either with GL_NEAREST or GL_LINEAR. I guess i'll try moving the texture coords in one pixel.
anyway, that's the update. any advice ?
#7
this is "zooming in" on the character by 0.5 texels on each edge (and adding a dropshadow effect):
it still has some slight bleed when the pixel size and texel size are similar, but it's pretty minimal, and might be an issue with minification rather than magnification.
just for fun, here's the same text but "zooming out" on each character:
.. it's interesting that the font page doesn't have the characters in alphabetical order.
08/17/2008 (12:19 pm)
W00t!this is "zooming in" on the character by 0.5 texels on each edge (and adding a dropshadow effect):
it still has some slight bleed when the pixel size and texel size are similar, but it's pretty minimal, and might be an issue with minification rather than magnification.just for fun, here's the same text but "zooming out" on each character:
.. it's interesting that the font page doesn't have the characters in alphabetical order.
#8
08/17/2008 (12:32 pm)
Looks awesome Orion! Any plans on releasing your mods? I would love to replace the static 2D floating text with this.
#9
right now it's tied to an object with custom rendering,
but we definitely plan to break it out of that, polish it, and make it a general-purpose thing.
so yes, but i'm not sure when.
also just ftr, a guy named Michael Plotz is doing the real work here.
08/17/2008 (12:44 pm)
Hey Peter!right now it's tied to an object with custom rendering,
but we definitely plan to break it out of that, polish it, and make it a general-purpose thing.
so yes, but i'm not sure when.
also just ftr, a guy named Michael Plotz is doing the real work here.
#10
03/24/2009 (6:42 am)
This looks great, it is exactly what I need, have there been any updates? Or is there a similar resource available?
#11
unfortunately things have been pretty busy and we haven't gotten around to resource-ifying this. i think it would probably take a half-day or maybe a bit more to package up so it works w/ stock TGE, which i don't really anticipate having the spare time anytime soon. the idea is definitely sound tho: just push a transform before calling dglDrawText().
dglDrawText() doesn't deal with linefeeds tho, so for multi-line text you need to split it into separate lines and change the transform for each.
i wish i could point you at a nice packaged resource; maybe in the future!
03/24/2009 (10:14 am)
Hey Ingo - unfortunately things have been pretty busy and we haven't gotten around to resource-ifying this. i think it would probably take a half-day or maybe a bit more to package up so it works w/ stock TGE, which i don't really anticipate having the spare time anytime soon. the idea is definitely sound tho: just push a transform before calling dglDrawText().
dglDrawText() doesn't deal with linefeeds tho, so for multi-line text you need to split it into separate lines and change the transform for each.
i wish i could point you at a nice packaged resource; maybe in the future!
#13
I have tried playing around with it, but had no luck so far. I am not an expert with OpenGL and the rendering in Torque. Could you maybe provide a little more code, including the setup of the matrices? Where should I actually put this code - for the testing I have added it directly into the player.cpp rendering methods. Have you implemented this for TGE only, or do you also know how it works with TGEA?
04/27/2009 (9:17 am)
Hi Orion,I have tried playing around with it, but had no luck so far. I am not an expert with OpenGL and the rendering in Torque. Could you maybe provide a little more code, including the setup of the matrices? Where should I actually put this code - for the testing I have added it directly into the player.cpp rendering methods. Have you implemented this for TGE only, or do you also know how it works with TGEA?
#14
04/27/2009 (10:05 am)
sure, i can post our source, but with the caveats that it's totally as-is, we haven't used it heavily, so it may have issues, and it may refer to other code that isn't part of stock TGE. good luck!
#16
04/28/2009 (9:20 am)
Great, thanks for the resource! I already started porting it to TGEA and I did get a first version running. However, as described above, the text looks pixelated at the moment and I didn't know how to port the gl calls. Do you know how to port the glDisable/glEnable, glMatrixMode, ... calls to the rendering system that is used in TGEA?
#17
unfortunately i haven't even dipped my little toe into TGEA,
but i imagine someone around GG could help.
it'd make a pretty nice resource if it were packaged up in a friendly way.
04/28/2009 (9:56 am)
sweet, glad you got something going here!unfortunately i haven't even dipped my little toe into TGEA,
but i imagine someone around GG could help.
it'd make a pretty nice resource if it were packaged up in a friendly way.
Associate Orion Elenzil
Real Life Plus