6
\$\begingroup\$

How would I go about rendering all Unicode characters?

Most font files don't include characters like these.

\$\endgroup\$
5
  • \$\begingroup\$ Why not use a font that supports them? \$\endgroup\$
    – Anko
    Nov 15 '15 at 23:04
  • \$\begingroup\$ Unless you let the OS do the font rendering for you: you can't. \$\endgroup\$
    – user253751
    Nov 16 '15 at 0:48
  • 2
    \$\begingroup\$ That is, you can't render characters that your font doesn't support, by definition. The question body asks a different question... \$\endgroup\$
    – user253751
    Nov 16 '15 at 1:51
  • \$\begingroup\$ ´@immibis How can I let the OS render text in my application? \$\endgroup\$
    – KaareZ
    Nov 16 '15 at 7:03
  • \$\begingroup\$ Please, your question is too broad, could you add more info about the platform you are developing in and any SDK or Tool kit you are using? \$\endgroup\$
    – user.dz
    Jan 20 '18 at 10:42
4
\$\begingroup\$

My approach is to do the following:

  1. Convert your font file to an image
  2. Store each character as a VAO (use a loop to store them all - array index = unicode number)
  3. Use a sprite batch to draw the text whenever its needed

Below is a snippet of my Java sprite batching code, used to draw the text.

public void draw(final String text, final float sx, final float y, final int layer) {
    float x = sx;
    for (final char c : text.toCharArray()) {
        this.draw(CHARACTERS.get(c), x, y, layer);
        x += 7 * this.scale;
    }
}

As for the font files not including the characters: if you don't have the characters to draw, you can't draw them, so you'll have trouble finding a sheet with all of these different characters.

\$\endgroup\$
4
  • \$\begingroup\$ -1. OP asks how to draw characters that he don't has in his font, not how to draw texts with ready font. Also, separate VAO for each character (and also matrix manipulations for each character) are expensive and introduce lots of draw calls. It's faster to have single VAO that is dynamically modified each time you need to draw a text. \$\endgroup\$ Nov 16 '15 at 18:10
  • \$\begingroup\$ @HolyBlackCat, I have addressed that drawing characters that you do not have is not possible. You do raise a good point about the matrices though. However, the shader that I use this with only accepts a vec2 uniform to position the letters, so that isn't a problem. Modifying a VAO each time is also more complicated and IMO, 36 bindings isn't that much each frame. \$\endgroup\$
    – Lolums
    Nov 16 '15 at 18:19
  • \$\begingroup\$ Oh, you lucky person. I have 256 glyphs in my fonts. :D So only solution for me is to modify a VBO each time. | About OPs question: Best solution for him is to find a font that contains almost every unicode symbol and use this font when his font does not have a needed glyph. It's better than just ignoring missing characters. So, saying that it's impossible is not best answer for this. \$\endgroup\$ Nov 16 '15 at 19:17
  • \$\begingroup\$ I see. In that case, you're right. However, I did not say that it is impossible. \$\endgroup\$
    – Lolums
    Nov 16 '15 at 20:19
4
\$\begingroup\$

If you cannot find a single font containing all glyphs you want, you will have to have multiple fonts.

Some text rasterisation APIs have "font linking" or "font substitution" in which they use more than one font as fallback for missing glyphs. This tends to result in a sub-optimal result in terms of character advances, relative glyph size, and kerning - but it at least shows something that may be recognizable as a glyph.

If you do your own rasterisation of individual glyphs, gather enough fonts with suitable licenses, rank then in order of preference and gather glyphs from them.

You may have to restrict yourself to a subset of character ranges -- do you really need every current codepoint in existence in your game?

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.