I'm writing a simple program to write characters 0-255 on the screen with the TTF addon. It is the first time I use the TTF addon so I'm a bit confused.
If I hardcode a string with extended ASCII characters as in:
al_draw_text(font, al_map_rgb(0, 0, 0), 0, 0, 0, "ÁÉÍÓÚÜ");
it works fine. But if try to initialize a char array and then draw the resulting string as in:
for (i = 0; i < 256; i++) text[i] = i + 1; al_draw_text(font, al_map_rgb(0, 0, 0), 0, 0, 0, text);
it only draws characters up to 127.
So, what's the trick here?.
Did you declare text as unsigned char[]?
Allegro uses UTF-8 as its text representation, not ASCII. The first 127 characters are the same in UTF-8 and ASCII, but anything above 127 is different. In fact, a byte the value of which is > 127 signifies many different things in UTF-8, none of which are single-byte characters. See this for more info.
OK. Thanks SiegeLord.
That said, this works:
for(int ii = 0; ii < 256; ii++) { char str[5]; int num_bytes = al_utf8_encode(str, ii); str[num_bytes] = '\0'; al_draw_text(font, al_map_rgb(255,255,255), (ii % 32) * 15, (ii / 32) * 25 + 10, 0, str); }
Supposedly that set of characters corresponds to a particular extended ASCII set of characters.
Oh, great!. I was just looking for a way to do this.
Thanks again.