GLFW 将代码点转换为 glfwCharCallback 中的字符
GLFW convert codepoints to characters in glfwCharCallback
我不知道如何在我的 glfwCharCallback 中解析字符中的代码点:
std::string currentText;
void char_callback(GLFWwindow* window, unsigned int codepoint)
{
// currentText += codepoint ???
}
...
glfwSetCharCallback(window, char_callback);
首先,您可以简单地将 unsigned int
截断为 unsigned char
并将其附加到您的 std::string
:
currentText += (unsigned char) codepoint;
请注意,对于超出基本 ASCII 的任何内容,这都是严重错误的。正如我在评论中所说,您可能想要存储 UTF-32 代码点以使用 freetype 进行渲染,或者转换为 UTF-8 以打印到控制台或存储。
我不知道如何在我的 glfwCharCallback 中解析字符中的代码点:
std::string currentText;
void char_callback(GLFWwindow* window, unsigned int codepoint)
{
// currentText += codepoint ???
}
...
glfwSetCharCallback(window, char_callback);
首先,您可以简单地将 unsigned int
截断为 unsigned char
并将其附加到您的 std::string
:
currentText += (unsigned char) codepoint;
请注意,对于超出基本 ASCII 的任何内容,这都是严重错误的。正如我在评论中所说,您可能想要存储 UTF-32 代码点以使用 freetype 进行渲染,或者转换为 UTF-8 以打印到控制台或存储。