如何从sdl_textinput获取UTF-8输入

How to get utf-8 input from SDL_TEXTINPUT?

本文关键字:获取 UTF-8 输入 textinput sdl      更新时间:2023-10-16

这是一个小型代码,当我们按"é"键或特殊字符的特殊字符时,我们会在控制台中获得奇怪的字符,例如"├®"。

#include <iostream>
#include "SDL.h"
using namespace std;
int main(int argc, char** argv)
{
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_CreateWindow("test", 100, 100, 1920, 1080, SDL_WINDOW_RESIZABLE);
    bool opened = true;
    SDL_Event event;
    while(opened)
    {
        SDL_StartTextInput();
        SDL_WaitEvent(&event);
        switch(event.type)
        {
            case SDL_QUIT:
                {
                    opened = 0;
                    break;
                }
            case SDL_TEXTINPUT:
                {
                    cout << event.text.text << endl;
                    break;
                }
        }
    }
    return EXIT_SUCCESS;
}

ps:我正在使用SDL 2

只需要使用 TTF_RenderUTF8_Blended进行渲染(文件中的输出很好)。