1

Here is a small code and when we press "é" key or special characters with for instance french keyboards, we get in the console weird characters such as "├®".

#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: I am using SDL 2

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
  • C++ has [pretty poor support for Unicode](https://stackoverflow.com/questions/17103925/how-well-is-unicode-supported-in-c11) - you can store a string encoded in UTF8, but you've got to be sure that whatever you give it to knows how to interpret it. `std::cout` likely doesn't know how to handle unicode, so it treats each `char` as ASCII, not as part of a UTF-8 sequence, hence your output. – hnefatl Dec 16 '17 at 18:00
  • Can your console handle utf8, e.g. can it display contents of utf8 file? (it can be on nix if locale and fonts are set correctly, not sure if it spossible on windows at all). At worst case you probably can write it to file instead, just make sure you don't do any conversions (e.g. file writer is set to 'binary' mode). – keltar Dec 17 '17 at 06:15

1 Answers1

0

Just have to use TTF_RenderUTF8_Blended for render (output in file was fine).

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33