- Home /
Text in Unity's GUI -- how is it done?
On iOS or Android,
What technology is used to render text, in GUI ?
Thus, is each letter a sprite, with a quad for each letter? Is it actually a text-mesh? (Ie each letter is a shaped mesh.) Is it done in some totally different way native to each platform?
What's the deal there? Cheers
Answer by pafla · Mar 20, 2014 at 03:40 PM
Very interesting question indeed. Some quick research yielded this:
When you set the Characters drop-down in the Import Settings to Dynamic, Unity will not pre-generate a texture with all font characters. Instead, it will use the FreeType font rendering engine to create the texture on the fly.https://docs.unity3d.com/Documentation/Components/class-Font.html
According to that text, they use quads with bitmap font characters from a texture atlas (or generated by FreeType). And that seems to be the same for all platforms.
Fascinating insight ...
so to be clear, in your interpretation,
here when unity says: Ins$$anonymous$$d, it will use the FreeType font rendering engine to create the texture on the fly. .........
do you think, what they are saying is:
they will use FreeType TO $$anonymous$$A$$anonymous$$E PNGS {ie, an alphabet sprite sheet} and then they USE QUADS - ONE QUAD FOR EACH CHARACTER to make a sentence.
and that is exactly what you are seeing in text in unity's GUI?
Is that your interpretation there?
in other words, it is identical, would be identical performance, to using any sprite-sheet-one-quad-per-character system (2dtoolkit, etc)
thanks!!
do you think, what they are saying is:
they will use FreeType TO $$anonymous$$A$$anonymous$$E PNGS {ie, an alphabet sprite sheet} and then they USE QUADS - ONE QUAD FOR EACH CHARACTER to make a sentence. Basically, yes. Although I doubt that they are creating compressed PNGs at runtime.
in other words, it is identical, would be identical performance, to using any sprite-sheet-one-quad-per-character system (2dtoolkit, etc)If you do not take possible optimizations into account, that would be the case. But there are several ways of increasing the performance of this technique, especially when it comes to managing the vertex data of the quads, so one can never be sure without accurate measurements.
If you are interested in the low-level aspects of this, Game Program$$anonymous$$g Gems 8 has an article by Aurelio Reis called "Fast Font Rendering with Instancing" that could be a good starting point for your research (lots of references in there too.)
That seems to be the size of it then, pafla - indeed then, even Unity's own "GUI" system, for text it is just rendering quads.
Someone has actually answered a challenging question (has this ever happened on this site before?! ;-) )
I guess in a sense I was hoping for some sort of access to the native (iOS or Android) text rendering, uh, technologies. But no.
Fascinating stuff ...
(Regarding optimizing that .. right. The G.P.G. books are awesome ain't they?)
Just BTW I notice you've only started using this forum, if you're new to Unity .. if you ever need character-shaped mesh (ie, 3D letters) there is a popular and well-loved package "flying text 3D" on the asset store. Cheers!
also just BTW if you're an experienced dev new to unity, you may have reach the point of "total an utter annoyance at throwing some text on the screen" :) for us the only realistic pipeline is to use 2dtoolkit and glyphdesigner - its the only pipeline we use for every client. notice my long comment here http://answers.unity3d.com/questions/384623/setting-font-size-according-to-screen-dpi.html (the one with images) - hope it helps!
Your answer
![](https://koobas.hobune.stream/wayback/20220613140719im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
iOS performance: GUItext? want to use text string, but how to instantiate and edit it runtime? 0 Answers
gui text button dont work 1 Answer
Editing certain words in a single NGUI Text Box 0 Answers
Fix Blurry UI text? 10 Answers
How long is a string? 3 Answers