在 OpenGL 上使用 freetype 字体渲染非英语 unicode 文本时出现问题

发布于 2024-08-20 19:01:35 字数 961 浏览 2 评论 0原文

我目前正在学习 NeHe 教程第 43 课 ( http://nehe.gamedev .net/data/lessons/lesson.asp?lesson=43)。该代码仅适用于英文文本,不适用于 Unicode 语言。幸运的是,我通过 NeHe 第 43 课的链接访问了 http://www.cs。 Northwestern.edu/~sco590/fonts_tutorial.html 并发现了另一个相同的教程示例,只有一个区别:它使用 w_char,并且该网站声称您可以在英语以外的语言上运行。

所以我尝试一下:

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

命名空间 freetype 的函数 print 的第四个参数是 *const unsigned Short** 所以我对它进行了类型转换。我还在长字符的双引号字符串前面放置了一个 L,并放入了一些亚洲字符以进行测试。

结果是所有的英文文本都可以正常显示,但是所有的泰文字符都变成了“[]B[]I[]5H[]8”。 [] 是方框。据我了解,这意味着该字体没有指定的语言,因此我尝试了其他字体,但所有其他泰语字体都给出了这些相同的方框。对于日语字体,也是一样的。所有盒子旁边都有一些英文字符。子字符串 öáæé 渲染得很好,没有任何问题。

我在这里忘记了什么吗?我们如何在这里显示非英语的 Unicode 语言?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜雨飘雪 2024-08-27 19:01:35

幸运的是,作者在他的网站上上传了他的教程的修改版本(在问题中指定),并且它使用 wchar_t (在原始版本中,作者使用 *const unsigned Short** 作为打印函数中的参数),这允许非英语语言。

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.

人间不值得 2024-08-27 19:01:35

看起来第 43 课中的 print() 甚至不具备 Unicode 功能。 NeHe 所做的只是为前 256 个 ASCII 字符创建 256 个显示列表,不接受 UTF8 字符串并将其转换为 FreeType 的 UTF32。

this 音译为 C++ 对我来说效果很好。

另外,获取 GNU Unifont 的副本,以确保您拥有所有 BMP

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文