无法在 GLFW window 标题中显示“ä”

Can't display 'ä' in GLFW window title

glfwSetWindowTitle(win, "Nämen");

变为 "N?men",其中“?”有点黑,扭曲的方块,说明无法显示字符。

如何显示“ä”?

如果要在 window 标题中使用 non-ASCII 个字母,则字符串必须采用 utf-8 编码。

GLFW: Window title:

The window title is a regular C string using the UTF-8 encoding. This means for example that, as long as your source file is encoded as UTF-8, you can use any Unicode characters.

如果您看到 一个黑色的、扭曲的小方块 那么这表明 ä 是使用某种非 UTF-8 的 iso 编码编码的,可能类似于拉丁语1。要解决此问题,您需要在编辑器中打开它,您可以在其中更改文件的编码,将其更改为 uft-8(无 BOM)并修复标题中的 ä

在这种情况下,GLFW 实现似乎不符合规范。可能该函数仍然使用 Latin-1 而不是 UTF-8。

我在 GLFW 3.3 Windows 64 位预编译二进制文件上遇到了同样的问题并修复了它:

SetWindowTextA(glfwGetWin32Window(win),"Nämen")