Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Extended characters with Allegro 4.9.21

This thread is locked; no one can reply to it. rss feed Print
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.
Marce.

Evert
Member #794
November 2000
avatar

You can input them as UTF-8 characters. See the ex_font example.

Thomas Fjellstrom
Member #476
June 2000
avatar

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.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Marce666
Member #12,216
August 2010

Thanks, but where should I look up those examples ?

Evert
Member #794
November 2000
avatar

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.
I also tried with utf8 but no extended characters appears.

In both cases, print function works until first extended characters is found.
In the attachment the resulting file.

Here the code:

#SelectExpand
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.

--
"Either help out or stop whining" - Evert

Marce666
Member #12,216
August 2010

Yes, my editor was set to Auto-dectect UTF8.
Still not working...
:(

Elias
Member #358
May 2000

Does ex_ttf work?

--
"Either help out or stop whining" - Evert

Thomas Fjellstrom
Member #476
June 2000
avatar

Make sure your font contains that particular character.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Kibiz0r
Member #6,203
September 2005
avatar

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"
Windows Allegro Build Repo: http://targonski.nazwa.pl/thedmd/allegro/

Marce666
Member #12,216
August 2010

Finally the problem was the encode of the main.pp file.
example ex_ttf.c works fine.

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 !!!!
Marce.
;)

Go to: