views:

372

answers:

2

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?

+1  A: 

It looks like print() in lesson 43 is not even anywhere near Unicode capable. All NeHe is doing is creating 256 display lists for the first 256 ASCII characters, not accepting a UTF8 string and converting it to UTF32 for FreeType.

Transliterating this into C++ has worked quite well for me.

Also, grab a copy of the GNU Unifont to make sure you have glyphs for all of the BMP.

genpfault
+1  A: 

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.

unknownthreat