[英]GLFW convert codepoints to characters in glfwCharCallback
I cant figure out how to parse the codepoint in a char in my glfwCharCallback:我无法弄清楚如何在我的 glfwCharCallback 中解析字符中的代码点:
std::string currentText;
void char_callback(GLFWwindow* window, unsigned int codepoint)
{
// currentText += codepoint ???
}
...
glfwSetCharCallback(window, char_callback);
As a start, you can simply truncate the unsigned int
to a unsigned char
and appending it to your std::string
:首先,您可以简单地将
unsigned int
截断为unsigned char
并将其附加到您的std::string
:
currentText += (unsigned char) codepoint;
Note that this is criminally wrong for anything beyond basic ASCII.请注意,对于基本 ASCII 以外的任何内容,这都是刑事错误的。 As I remarked in the comments, you probably want to either store UTF-32 codepoints for rendering using freetype, or convert to UTF-8 for printing to console or storage.
正如我在评论中所说,您可能想要存储 UTF-32 代码点以使用 freetype 进行渲染,或者转换为 UTF-8 以打印到控制台或存储。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.