このページに従って、コールバック (glfwSetCharCallback を使用して設定) を使用して GLFW からユーザー入力を読み取っています: http://www.glfw.org/docs/latest/input.html#input_char
コールバック関数は、押されたキーを 32 ビットの unsigned int として受け取ります。これを画面に印刷できるものに変換するにはどうすればよいですか? C++11 の codecvt と ICU ライブラリの両方を試しましたが、端末に読み取り可能な文字を出力するものは何もありませんでした。
これは私のコールバック関数のコードです:
void InputManager::charInputCallback(GLFWwindow* window, unsigned int key)
{
UErrorCode errorStatus = U_ZERO_ERROR; //initialize to no error
UConverter *utf32toUnicode = ucnv_open("UTF-32", &errorStatus); //create converter utf-32 <=> Unicode
if(U_FAILURE(errorStatus))
std::cout << u_errorName(errorStatus) << std::endl;
UChar unicode[10] = {0};
ucnv_toUChars(utf32toUnicode, unicode, 10, (char*)key, 4, &errorStatus); // this fails with an U_ILLEGAL_ARGUMENT_ERROR
if(U_FAILURE(errorStatus))
std::cout << u_errorName(errorStatus) << std::endl;
std::cout << unicode << std::endl;
}
入力 (キー) に何もしないと、何も表示されません。ただの空白行。