|
Bitmap Font doesn't draw any character after try to write a not defined char |
chanochambure
Member #15,725
September 2014
|
I was using al_draw_scaled to draw this string that has a 'á' NON ASCII Character, this char was not defined on my bitmap font. 1footer_trademark = "Mega Man X is á registered trademark of Capcom Co., Ltd.";
I wanted to draw the other characters instead got this 'error' |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Undefined behavior is undefined... So, don't do that? My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Peter Hull
Member #1,136
March 2001
|
What function are you using? al_draw_scaled ??
|
chanochambure
Member #15,725
September 2014
|
1void Text::draw()
2{
3 ALLEGRO_TRANSFORM al_transform;
4 al_identity_transform(&al_transform);
5 al_scale_transform(&al_transform, _V_scale_x*bitmap_scale_x, _V_scale_y*bitmap_scale_y);
6 al_translate_transform(&al_transform,_V_pos_x,_V_pos_y);
7 al_use_transform(&al_transform);
8 al_draw_text(*_V_font,_V_color,0,0,_V_flag,_V_text.c_str());
9 al_identity_transform(&al_transform);
10 al_use_transform(&al_transform);
11}
I'm using the function al_draw_text to draw the text _V_text with my font _V_font that was my bitmap font. The problem is that i wanted to draw the text that the following joystick functions return me, and this values (for example in spanish) return me non-ascii characters like 'Botón 1'
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
So use a bitmap font with those characters in it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Peter Hull
Member #1,136
March 2001
|
I tracked through the code a bit and it seems that Allegro uses only the ANSI variants of the APIs (I am assuming you're using Windows?) so it probably is returning the names with characters from whatever code page you are using. (presumably 1252 Ansi Latin 1)
|
Elias
Member #358
May 2000
|
If the encoding is UTF16 then á will be encoded as \xe1\x00 and the "\x00" byte will terminate the string. -- |
Peter Hull
Member #1,136
March 2001
|
If the encoding is UTF-16 then all ascii characters will be encoded as <something>\x00 and the \x00 byte will terminate the string.
|
Peter Hull
Member #1,136
March 2001
|
Alright but has anyone go a bitmap suitable for feeding to al_grab_font_from_bitmap?
|
chanochambure
Member #15,725
September 2014
|
There is my Font that i was using to draw my text, may the 'fallback' character has a code on ASCII to set up with al_grab_font_from_bitmap. Or maybe this is the problem of an unicode that has the null character \x00. I wanted to show the name of the button of the joystick that a user want to use in my game to configure the game controls, but imagine for example in spanish the button name return "Botón 5" with ó on another encoding, that allegro cannot find the ó and print at least something like "Botn 5", to doesnt break that controls configuration is working! |
Peter Hull
Member #1,136
March 2001
|
I see it too. I will investigate.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
You could write a program to read in a ttf file, and output a bitmap font. In theory it should be simple enough. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Peter Hull
Member #1,136
March 2001
|
What happens is: Unfortunately al_ref_cstr does not 'create a UTF-8 string', it just references the data in a C string as if it were UTF-8. So, when al_ustr_get_next comes to the 0xD3, it sees this as an invalid UTF-8 code, returning '-2', and this in turn causes color_render to stop. Hence no more characters are printed.
In any case the docs for al_draw_text and friends should be a bit more specific on the input - they take UTF-8 and not just any C-string. If anyone has any more thoughts please post them - might be worth filing an issue on github for this. Example program: 1#include <allegro5/allegro.h>
2#include <allegro5/allegro_font.h>
3#include <allegro5/allegro_image.h>
4
5int ranges[] = {
6 0x0020, 0x007F, /* ASCII */
7};
8const char* GOOD="Boton GOOD";
9const char* BAD="Bot\323n BAD";
10
11int main(void) {
12 al_init();
13 al_init_font_addon();
14 al_init_image_addon();
15 ALLEGRO_DISPLAY* display = al_create_display(640,480);
16 ALLEGRO_BITMAP* mmx = al_load_bitmap("mmx12_font_f1.png");
17 ALLEGRO_FONT* font = al_grab_font_from_bitmap(mmx, 1, ranges);
18 al_draw_text(font, al_map_rgb(0x80, 0xff, 0x80), 5.0f, 5.0f, 0, GOOD);
19 al_draw_text(font, al_map_rgb(0xff, 0x80, 0x80), 5.0f, 50.0f, 0, BAD);
20 al_flip_display();
21 al_rest(10);
22 return 0;
23}
Output:
|
|