- Home /
Low level text writing
I am using Unity's low-level Graphics/GL classes to do the in-game HUD instead of Unity's GUI due to performance reasons.
I've managed to get it to work and it's great, the only problem that remains is texts. We've managed to get most of them done by creating textures that represent characters and using Graphics.DrawTexture(). We've done this for numbers (score, hit points etc) but for other texts we've used a plain texture (i.e the word "Score" is a single texture).
So obviously this isn't ideal and now we have the problem of wanting to use different scales (score announcements in different sizes etc).
My question is: is there a low-level parallel of Graphics.DrawTexture() for writing texts in a given font? Or perhaps there is a way to do that from building blocks? I've looked for example at the texture in the imported font file but couldn't figure out how it's meant to be used.
Any ideas?
PS "I am using Unity's low-level Graphics/GL classes to do the in-game HUD" totally awesome, you rock. any chance of a vid or something of how good it works
No vid yet but I can post a code snippet if you are interested. It is actually quite simple for images. But bear in $$anonymous$$d that by "HUD" I mean the non-interactive in-game HUD. When we need buttons and such we use Unity's normal GUI system (i.e for menus etc). But when the actual game is running, we don't need those.
Sure: http://pastebin.com/LmkshtFz
These are just examples but I think you get the drift from them. The HUD class uses a similar technique to the one displayed in the Cursor class to call the method you see there (i.e coroutine with WaitForEndOfFrame).
RE rotating images I haven't implemented something like that, I don't know if it's possible with Graphics.DrawTexture(). I'll have to think about it.
You might have a look at FlyingText3D, which creates meshes from TrueType fonts. (The text doesn't have to be actual 3D as in extruded, it can happily be flat 2D text. Although still technically 3D, which means it's vector-based and fully resolution-independent.)
Answer by Fattie · Jun 23, 2012 at 08:53 PM
I'm fairly sure there is NOT a way to do this. It's my "most wanted thing"
In short NO, SADLY, YOU MUST USE DIFFERENT SIZE LETTERS FOR DIFFERENT SCREENS.
The standard solution at the moment is either A or B:
A include different sizes for the different screens it will be running on
B include only the "largest" size, and scale down for the "smaller" sizes (wastes a little space)
or I guess C include only the small size, and scale up (results in blurry)
I urge you to get 2dToolkit which completely handles font-like textures. (they are just textures .. with "letters on them") I'd guess that in combination with your system would be ideal. if you get it now you'll be smiling in 30 minutes. (But you still have to choose A B or C, to be clear.)
I spend about 90% of my life emailing people like the makers of the various GUI kits, 2dToolkot, and Unity, whining that they should
BUT ..
.
it looks like Unity4, in fact, finally has dynamic fonts. This is HUGE, HUGE news.
it would be utterly pointless implementing anything at this point, since, U4 will be here soon enough.
I hope this helps in some way. You have stumbled on to the hugest most annoyingest problem in Unity But it looks like they fixed it in 4.
I feel really bad for anyone who was hand-building a proper dynamic font maker - which would have been a mega-money-maker on the asset store.
Just FTR if you hassle all the folks who make gui-replacement-kits, N-d toolkits and the like, they, also, suggest precisely "A" and "B" above ... unfortunately that's about it.
I can't even begin to describe how much I've cursed and spat blood over the GUI over the past months. Perhaps sometime I will post the code I've written that wraps Unity's immediate mode GUI in a retained widget like API.
I often thought about starting an open source project of a full replacement GUI system for Unity (I was thinking of integrating CEGUI). However the knowledge that the new GUI system is "just around the corner" always stopped me.
Anyway, water under the bridge now. We'll ship our game soon and our next project hopefully will be based on Unity 4 and we'll forget all about the nightmares we had with the GUI in the past...
Funny isn't it - here I am with my RetainedGUI class I was thinking of pushing out there as well :)
@Fattie - huge news! Fantastic!
The whole GUI situation is a ####ing joke. #### Unity and the ####ing donkey they rode in on. ####ing ####ers.
A ####ing 10-year old would realize you need to capture ####ing events off ####ing buttons and that you can't have ####ing performance problems in a ####ing gui layer in a ####ing product we all pay $1500 a seat for every couple ####ing years and it can't even do ####ing hel-####ing-vetica dynamically given the whole ####ing idea of the ####ing product is that it makes ####ing games on many DIFFERENT ####ing platforms. #### !!!!
they're ###ing ####holes.
I've lost count of the number of times I had a post like this ready in the forums and deleted it... yes, they really dropped the ball with the GUI. Amir's golden rule #1 (learned the hard way): Never ever architect to syntax! But no one can build a perfect system, they've done a terrific job all around, there were bound to be a few slips.
Unity already has dynamic fonts and has had them for some time, the only thing is they don't work on mobile platforms (yet).
Your answer
Follow this Question
Related Questions
GUI text font change 3 Answers
Limit on GUI Components? 0 Answers
Using "fonts" that are actually images for a multi-outline effect. 2 Answers
Dialouge text. 1 Answer
iphone album art how? 0 Answers