allegro5 text no output why?

hi guys

i'm south korean allegro user

i am not good at english.

Sorry, but I don't speak English well.

(please understand even if you can't understand me clearly)

1#include <allegro5/allegro.h> 2#include <allegro5/allegro_native_dialog.h> 3#include <allegro5/allegro_ttf.h> 4#include <allegro5/allegro_font.h> 5 6#define ScreenWidth 800 7#define ScreenHeight 600 8 9int main(int argc, char **argv) 10{ 11 ALLEGRO_DISPLAY *display = NULL; 12 ALLEGRO_FONT *font; 13 ALLEGRO_USTR *ustr; 14 15 al_init(); 16 17 al_set_new_display_flags(ALLEGRO_WINDOWED); 18 display = al_create_display(ScreenWidth,ScreenHeight); 19 al_set_window_position(display,200,100); 20 al_set_window_title(display,"CodingMadeEasy"); 21 al_clear_to_color(al_map_rgb(0,0,0)); 22 23 al_init_font_addon(); 24 al_init_ttf_addon(); 25 font = al_load_font("C:\\WINDOWS\\Fonts\\L_10646.ttf",36,NULL); 26 27 // Success Output 28 al_draw_text(font,al_map_rgb(44,117,255),ScreenWidth/2,ScreenHeight/2,ALLEGRO_ALIGN_CENTER,"Coding Mady Easy"); 29 // Fail No Output why??? 30 al_draw_text(font,al_map_rgb(44,117,255),ScreenWidth/2,ScreenHeight/2+36,ALLEGRO_ALIGN_CENTER,"코딩은 쉽다"); 31 32 // Success Output 33 ustr = al_ustr_new("Hello"); 34 al_draw_ustr(font,al_map_rgb(44,117,255),0,0,0,ustr); 35 al_ustr_free(ustr); 36 // Fail No Output why??? 37 ustr = al_ustr_new("안녕하세요"); 38 al_draw_ustr(font,al_map_rgb(44,117,255),0,36,0,ustr); 39 al_ustr_free(ustr); 40 41 al_flip_display(); 42 al_rest(3.0); 43 al_destroy_display(display); 44 45 return 0; 46}



Edgar Reynaldo

I think you need to save your source file as UTF-8 before it will work.


Edgar Reynaldo// ㅜ0ㅜ im text output failed but Thank you comment


Well, al_draw_text cannot draw non-ASCII text. But al_draw_ustr will work IF you make sure the strings in your C file are in UTF-8 format. ISO-2022-KR or EUC-KR will NOT work. Allegro supports UTF-8 only.

Peter Wang
beoran said:

al_draw_text cannot draw non-ASCII text

It can, but the string must be UTF-8 encoded.


Ah? I didn't know that. Thanks for mentioning that here! :)

It's not mentioned in the manual, it seems, so I'll see if I can contribute a patch for the manual that clarifies this.


i'm this source file is utf-8 encoding later build play but no text output (T0T)

Edgar Reynaldo

Attach the font that you are using so I can test this on my laptop. I don't know how to get CodeBlocks to display chinese characters though, so I can't tell if I'm doing it right yet.


Jiāng nín suǒ shǐyòng de zìtǐ, suǒyǐ wǒ kěyǐ cèshì wǒ de bǐjìběn diànnǎo shàng. Wǒ bù zhīdào zěnme nòng mǎ kuài suīrán xiǎnshì zhōngwén zìfú, suǒyǐ wǒ bùnéng gàosu rúguǒ wǒ hái zhèyàng zuò shì zhèngquè.

(Just google translate)


Edgar Reynaldo//

yes attach my font

l_10646.ttf // i employ font

맑은고딕.ttf // my country korea text font

you success please



The font you are using, L_10646.ttf, does NOT support Korean in Allegro. Probably it does not support Unicode encoding.

I attached an open-source Korean font (which you can use freely with your program). When I use the font as in the attached program korean.c , and put it in the same directory as the program when I execute it, it works.

For Allegro, it is best to always use open source fonts, and distribute those with our program. Never use the fonts that come with Windows. Because, some people will not have that font. I hope this solves your problem.


beoran, Thank you and sorry your korean.c source i

i have questions


↓↓↓ korean.c source file comfile result ↓↓↓



korean characters be cut off why??


When I run this program (on Linux, compiled using GCC), the whole Korean string displays without problems. I think the ? means that the encoding of the korean.c file somehow isn't UTF-8 anymore.

Perhaps you should try not to use MSVC, and in stead download ad install mingw and a good source editor, perhaps notepad++, in which you can set the source encoding on saving to UTF-8 correctly.

Peter Wang

The problem is that it is very hard to convince MSVC output UTF-8 encoded strings unchanged in the executable. You can probably find some information about it on Korean web pages, as it is hard to explain.

One solution that works everywhere is to move your strings into an external file. For example, ex_ttf.c and ex_ttf.ini


Oh my... it seems that like Peter says, MSVC starting from 2008 does indeed miscompile UTF-8 strings. See here for more information:

I recommend switching to MINGW and a different IDE like CodeBlocks, more specifially Get the version that has MINGW included, it should be the easiest for you to install.

If you must use MSVC 2010, then applying this hotfix + using #pragma execution_character_set("utf-8") might help:

Or you could try to save the file in UTF-8 without BOM. Although I read that that doesn't always work.

EDIT: I changed the korean.c program to use the attached koran.ini as config file for its text. I have a section [english] for english text and [korean] for korean text. Like this, it's easy to translate the application based on the user's language. All files go in the same directory, of course.



beoran and peter wang Thank you for teaching me

very very Thank you

solve a problem

i'm korea programming forum

Your teaching Share information with your name

real very very Thank you


You are welcome. :)

I hope you'll have a lot of fun learning how to program in C using Allegro.

Slaweek Shpachenko

I still can't make it work with Cyrillic text. I tried to use TTF font with Latin and Cyrillic symbols in it (70KB). In result Latin symbols is printed, but Cyrillic is only clean space... Then i tried Unicode 6.2 TTF font (22MB). I've got the same result. Even if i use ALLEGRO USTR I've got the same...
There's my recent try to discuss (only close to theme part of code):

1#include <allegro5/allegro.h> 2#include <allegro5/allegro_font.h> 3#include <allegro5/allegro_ttf.h> 4#include <allegro5/allegro_image.h> 5#include <string> 6#include <stdio.h> 7 8int main (int argc, char **argv){ 9al_init(); 10al_init_font_addon(); 11al_init_ttf_addon(); 12al_init_image_addon(); 13 14bool game_over = false; 15 16int disp_w = 1024; 17int disp_h = 768; 18ALLEGRO_DISPLAY disp = al_create_display(disp_w, disp_h); 19ALLEGRO_BITMAP *fon0 = al_load_bitmap("fon0.jpg"); 20ALLEGRO_USTR *testuni = al_ustr_new("Crazy Выхухоль"); 21ALLEGRO_FONT *italy = al_load_ttf_font("Italy B.ttf", 75, 0); 22ALLEGRO_FONT *uni = al_load_ttf_font("uni.ttf", 75, 0); 23 24while (game_over==false){ 25 26al_draw_ustr(uni, al_map_rgb(255,255,255), disp_w/2 - 100, disp_h/2 + 200, 0, testuni); 27al_draw_text(italy, al_map_rgb(255,255,255), disp_w/2 + 100, disp_h/2 + 200, 0, "Crazy Выхухоль"); 28al_flip_display(); 29al_draw_scaled_bitmap(fon0, 0, 0, al_get_bitmap_width(fon0), al_get_bitmap_height(fon0), 0, 0, disp_w, disp_h, 0); 30} 31al_destroy_display(disp); 32al_destroy_font(italy); 33al_destroy_font(uni); 34}

And result: only "Crazy" printed, without "Выхухoль"

By the way: i search in data files of another allegro based games and look what i found: in a game with Cyrilic text 2 files - font01.PCX (21KB) and font01.TXT with "Font01.pcx 0x22 0xFF" inside. Maybe it helps solve the problem.


Slaweek Shpachenko, I think thatyour problem is exactly the same as visual00's pronblem. That is, you're using MSVC on Windows, and MSVC from version 2008 doesn't support UTF-8 encoded text in the source code. On Linux, your code displays the Russian fine. You must use text files, or a different compiler like MINGW to get it to work.

Thread #612879. Printed from