![]() |
|
Extended characters with Allegro 4.9.21 |
Marce666
Member #12,216
August 2010
|
Hi, I wanna known how in Allegro 4.9.21 can I write characters like áçñÑè among others. Using .TTF (TrueTypeFonts) I used to use set_uformat(U_ASCII) in Allegro 4.2 but I cannot found an equivalent here. Thanks in advance. |
Evert
Member #794
November 2000
![]() |
You can input them as UTF-8 characters. See the ex_font example. |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Marce666 said: I wanna known how in Allegro 4.9.21 can I write characters like áçñÑè among others. Allegro 5's new string api uses utf8. So you can generally just use utf8 anywhere and it ought to work. Though I think things will work more reliably if you use the _ustr functions when you have the option, rather than the functions that take plain char*. like al_draw_ustr rather than al_draw_text. -- |
Marce666
Member #12,216
August 2010
|
Thanks, but where should I look up those examples ? |
Evert
Member #794
November 2000
![]() |
In the example/ directory that comes with Allegro. |
Marce666
Member #12,216
August 2010
|
Example of ex_font doesn't helps me because I have to use TrueTypeFont. In both cases, print function works until first extended characters is found. Here the code: 1al_init();
2al_init_font_addon();
3al_init_ttf_addon();
4al_init_image_addon();
5al_init_primitives_addon();
6
7display = al_create_display(320, 200);
8al_draw_filled_rectangle(0, 0, 320, 200, al_map_rgb(0, 0, 180));
9
10ALLEGRO_FONT * pFont = al_load_ttf_font("ARIAL.TTF", 30, 0);
11ALLEGRO_USTR * pText = al_ustr_new("Hello á Bye");
12
13//draw with ALLEGRO_USTR
14al_draw_ustr(pFont, al_map_rgb(255, 255, 0), 10, 10, ALLEGRO_ALIGN_LEFT, pText);
15
16// draw with char *
17al_draw_text(pFont, al_map_rgb(255, 0, 0), 10, 50, ALLEGRO_ALIGN_LEFT, "Hello ñ Bye ");
18
19ALLEGRO_BITMAP * pBitmap = al_get_backbuffer(display);
20if (pBitmap)
21 al_save_bitmap("file1.bmp", pBitmap);
Any idea ? Thanks, Marce. |
Elias
Member #358
May 2000
|
In your editor, make sure the file is encoded as UTF8. -- |
Marce666
Member #12,216
August 2010
|
Yes, my editor was set to Auto-dectect UTF8. |
Elias
Member #358
May 2000
|
Does ex_ttf work? -- |
Thomas Fjellstrom
Member #476
June 2000
![]() |
Make sure your font contains that particular character. -- |
Kibiz0r
Member #6,203
September 2005
![]() |
I've never done unicode in C/C++, but I've seen L"some unicode string" before... Try that? --- |
Peter Wang
Member #23
April 2000
|
That's the syntax for a wide character strings, which is too ambigous to be usable in portable programs. Allegro only accepts UTF-8 encoded strings.
|
Michał Cichoń
Member #11,736
March 2010
|
When you source code is in UTF-8 every string you put in will work with Allegro. UCS-2 (L"" syntax) is supported in modern compilers, but usually there are not standard libraries which allow to convert between UCS-2 and UTF-8. Allegro have handy routines to deal with such conversion, look at al_utf8_width() and al_utf8_encode(). In case, when you want full Unicode support you need to use native system routines or external library. "God starts from scratch too" |
Marce666
Member #12,216
August 2010
|
Finally the problem was the encode of the main.pp file. Eventhought UTF-8 was in auto-detect mode (Visual Studio 2010 express), each file has to be save as unicode-UTF8. Save File AS -> Save with encoding -> Unicode (UTF-8 widthout signature) - Codepage 65001 Nota: I have to save to another encode, save, close (IDE), open and then set the correct codepage. Thanks All !!!! |
|