c++ - Rendering font with UTF8 in SDL_ttf -


i trying render characters using ttf_renderutf8_blended method provided sdl_ttf library. implemented user input (keyboard) , pressing 'ä' or 'ß' example works fine. these special characters of german language. in case, in extended ascii 8-bit code, when copy , paste greek letters example, fonts rendered correctly using utf8. (however not all unicode glyphs can find here (http://unicode-table.com/) able render recognized during testing guess normal because arial font might not have every single glyph. anyways of unicode glyphs work fine.)

my problem passing strings (parameter const char*) additional characters (to ascii) aren't rendered correctly. entering 'Ä', 'ß', or other unicode chars keyboard @ runtime works passing them parameter - let's title game - inside code not work:

font_srf = ttf_renderutf8_blended(font, "hällö", font_clr); 

i don't understand why happening. on screen is:

h_ll_
, using _ represent typical vertical rectangle guy gave following speech used funny way of introduction: https://www.youtube.com/watch?v=mw884plutw8

ironically, when use ttf_rendertext_blended(font, "hällö", font_clr); works because 'ä' , 'ö' 8-bit extended ascii encoded, want unicode support, not help.

edit & semi-solution

i kind of (not good) fixed problem, because input works fine, checked values input when press 'ä', 'ß', ... on keyboard using following code:

const char* c = input.c_str();  (int = 0; < input.length(); i++) {     std::cout << int(c[i]) << " "; } 

then printed characters in following way:

const char char_array[] = {-61, -74, -61, -97, '\0'}; const char* char_pointer = char_array; 

-61, -74 'ö' , -61, -97 'ß'. fit utf8 encoding right?

  • u+00f6 | ö | c3 b6 (from utf8 data table)
  • 256-61=195 c3
  • and 256-74=182 b6

    const char char_array[] = {0xc3, 0xb6};

this code works fine in case of wondering. , think keep doing now. looking hex-code unicode glyphs isn't hard.

but still can't figure out how extended ascii integer value of 246. plus, isn't there more human-friendly solution problem?

if have non-ascii characters in source file, character encoding of source code file matters. in text editor or ide, need set character set (e.g. utf-8) when save it.

alternatively, can use \x... or \u.... format specify non-ascii characters using ascii characters, source file encoding doesn't matter.

microsoft doc, not ms-specific:

https://msdn.microsoft.com/en-us/library/6aw8xdf2.aspx


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo