openglunicodefontsfreetypeasianfonts

Problem rendering non-English unicode text using freetype font on OpenGL


I am currently following NeHe tutorial lesson 43 ( http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=43). The code works satisfactorily only for English text, not Unicoded languages. Fortunately, I follow a link from NeHe lesson 43 to http://www.cs.northwestern.edu/~sco590/fonts_tutorial.html and found another identical tutorial sample with only one difference: it uses w_char, and the site claims that you can run on a language other than English.

So I give it a try:

freetype::print(our_font, 320, 200, (unsigned short*)L"Active FreeType Text หกโด้กี่ดุ öáæé おはよ。- %7.2f", cnt1);

the function print of namespace freetype has the 4th argument as *const unsigned short** so I typecasted it. I also put an L in front of the double quoted string for long characters and put in some Asian characters for testing purpose.

The result is all the English text can displayed just fine, but all the Thai characters become "[]B[]I[]5H[]8". The [] are square boxes. From what I understand, this implies that the font does not have the specified language, so I tried out other fonts, but all other Thai fonts give out these same square boxes. For the Japanese font, it is the same. All boxes along with some English characters next to them. The substring öáæé is being rendered just fine without any problem.

Am I forgetting something here? How can we display non-English Unicode language here?


Solution

  • Fortunately, the author has uploaded a modified version of his tutorial in his website (specified in the question) and it uses wchar_t (in the original version, the author uses *const unsigned short** as an argument in the print function), which allows non-English languages.