游戏中的Unicode输入处理 [英] Unicode Input Handling in Games

查看:403
本文介绍了游戏中的Unicode输入处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个游戏,要求我允许玩家通过网络互相聊天。一切都很好,除了玩家可以输入Unicode输入的部分。



所以,问题可以分为两部分:




  • 当玩家输入时,如何捕获输入?我通过游戏输入处理


  • 在将输入捕获到字符串之后,如何使用TrueType字体输出? em>我问这个的原因是因为通常,我将在游戏开始时从游戏中使用的所有文本构建位图字体。但是使用unicode输入,需要接近10k个字符,这在游戏开始时是不可能的。




p PS

解决方案

对于输入


  1. 使用 SDL_EnableUNICODE 以启用unicode输入处理

  2. 照常接收 SDL_KeyboardEvent

  3. 使用 unicode %5Fkeysym> SDL_keysym 以获取unicode

用于呈现 b
$ b

如果所需的字体大小相当小,例如16px,你实际上可以将它全部渲染到一个单一的纹理,你可以适应至少4096字形在1024x1024纹理在那个大小,一个当您进行紧缩打包时(请参阅 fontgen 的示例代码)更多一些。



如果你不想使用更大的纹理尺寸,你可以使用更大的纹理尺寸。按需生成字体,只需像往常一样创建Texture,然后使用

另一个选择是不要使用纹理来绘制字形,而是针对文本本身使用纹理,这是一个很好的选择。gtxsubimage2d.html> glTexSubImage2D to upload new glyphs to the texture。这样你绕过所有的字形生成产生的麻烦。但它对于非静态可编辑文本可能不是一个好主意。


I have a game that requires me to allow players to chat with each other via network. All is well, except the part where players can type in Unicode input.

So, the question can be split into two parts:

  • When players type, how do I capture input? I have done this before via the game input handling (polling), however, it is not as responsive as something like Windows Forms.

  • After I capture input into a string, how do I output it using TrueType Fonts? The reason I ask this is because usually, I would build bitmap fonts at the start of the game from the all the text used in the game. But with unicode input, there are nearly 10k characters that are needed, which is quite impossible to build at the start of the game.

P.S. My target input languages are more specific to Chinese, Korean and Japanese.

解决方案

For Input

  1. Use SDL_EnableUNICODE to enable unicode input handling
  2. Receive the SDL_KeyboardEvent as usual
  3. Use the unicode member of SDL_keysym to get the unicode

For Rendering

If the needed font size is reasonably small, say 16px, you actually could just render it all to a single texture, you can fit a minimum of 4096 glyphs on 1024x1024 texture at that size, a bit more when you pack them tightly (see fontgen for example code). That should be enough for common chat, but not enough to fit all the glyphs of a TTF file.

If you don't want to use a larger texture size you have to generate the fonts on demand, to do that just create the Texture's as usual and then use glTexSubImage2D to upload new glyphs to the texture.

Another alternative is to not use textures for glyphs, but for the text itself. That way you bypass all the trouble that glyph generation produces. But its probably not such a good idea for non-static editable text.

这篇关于游戏中的Unicode输入处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆