# Designing unicode font system (freetype)

This topic is 3874 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to add unicode support for texts in my engine. The idea for non-unicode texts was simple, just prebuild all of the letters, numbers, ... to a texture, this was of course possible because the count was maximum of 256. The unicode char set contains 256*256 possible glyphs, so prebuilding that doesn't seem like an option. The thing that comes to mind is to dynamicly build glyph textures when they are requested for the first time, that can of course produce lags when first few texts are rendered. The solution for this would be to prebuild some of the expected glyphs (latin alphabet for english versions, cyrilic for russian... ) The only problem that comes in mind for this is that it would use a large number of gl textures and display lists, would this be a problem? Also what would be the best way to store texture pointers, seperatly for every font used ... i was thinking something in line of: struct glyph{ unsigned texID; unsigned listID; bool built; }; struct font{ glyph font_glyphs[256*256] // it would be set to glyph.build = false };

##### Share on other sites
Quoth Wikipedia:

Quote:
 Unicode defines a codespace of 1,114,112 code points in the range 0x0 to 0x10FFFF

now, I'm pretty sure all of those code points aren't used at the moment, but to say that you support unicode printing with a mere 65,536 chars (256*256) would be innacurate. I don't have an answer for you right away (I've been doing research on this myself), but I wanted tp point out that you may be artificially limiting yourself with your current numbers.

One good resource to check out would be this Text rendering Tutorial which uses freetype and supports unicode. It's written in D and uses OpenGL, but the basic principles shouldn't be too hard to implement anywhere.

[EDIT]
Ooh! Also, if you haven't already, go read this! It's an excellent and quick intro to the basic concepts of Unicode that every programmer should know.

##### Share on other sites
ok, i'll probably have:

class glyph{public:  glyph(): loaded(false) {}  unsigned textureID;  bool loaded;}class font{public:  vector<glyph> glyphs;  int size;  font(): size(10) {}  unsigned getGlyphTexture( wchar_t character )  {    if(glyphs.size()<=character)    {      glyphs.resize(character+1, glyph());      generateGlyph( &glyphs[character].textureID, character );      glyphs[character].loaded = true;    }  }};void drawText( wstring aText, font *aFont ){  for (int i = 0; i < aText.size(); i++)  {    glBindTexture(GL_TEXTURE_2D, aFont->getGlyphTexture(aText) );    .... //render  }}

also now I think that the use of display lists in this dynamic system wouldn't be very usefull.

##### Share on other sites
There is a lot more to do than using unicode to add support to different languages. Some languages are very different from English and follows several rules that you should know to set them in the correct way. Arabic for example have different form for every letter (based on the position in the word). In some languages you should reorder the letters in some situations.

In general a single set of glyphs is used at any time so you can cache only the sets you need. You can load and cache glyphs based on need and then free the space used when they are no longer used.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 25
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634098
• Total Posts
3015524
×