Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » allegro5 text no output why?

This thread is locked; no one can reply to it. rss feed Print
allegro5 text no output why?
visual00
Member #15,194
June 2013

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)

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

{"name":"xozg.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/b\/8bc80dc0dc8ee199bcb83859007c3dc6.jpg","w":923,"h":329,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/b\/8bc80dc0dc8ee199bcb83859007c3dc6"}xozg.jpg

{"name":"pnuu.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/d\/cd914853bb0fffeb967f724356fdc0d8.jpg","w":500,"h":388,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/d\/cd914853bb0fffeb967f724356fdc0d8"}pnuu.jpg

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

visual00
Member #15,194
June 2013

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

beoran
Member #12,636
March 2011

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
Member #23
April 2000

beoran said:

al_draw_text cannot draw non-ASCII text

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

beoran
Member #12,636
March 2011

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.

visual00
Member #15,194
June 2013

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

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

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)

visual00
Member #15,194
June 2013

Edgar Reynaldo//

yes attach my font

l_10646.ttf // i employ font

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

you success please

beoran
Member #12,636
March 2011

visual00,

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.

visual00
Member #15,194
June 2013

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

i have questions

um...

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

1.
{"name":"ovin.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/9\/2911c9bf7387ead4ea008a20da65a8dc.jpg","w":1280,"h":768,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/9\/2911c9bf7387ead4ea008a20da65a8dc"}ovin.jpg

2.
{"name":"pxdz.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/3\/b35e25ee189d328ba610adf752c836e0.jpg","w":1016,"h":736,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/3\/b35e25ee189d328ba610adf752c836e0"}pxdz.jpg

korean characters be cut off why??

beoran
Member #12,636
March 2011

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 http://mingw.org/ and a good source editor, perhaps notepad++, in which you can set the source encoding on saving to UTF-8 correctly.

Peter Wang
Member #23
April 2000

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

beoran
Member #12,636
March 2011

Oh my... it seems that like Peter says, MSVC starting from 2008 does indeed miscompile UTF-8 strings. See here for more information: http://stackoverflow.com/questions/688760/how-to-create-a-utf-8-string-literal-in-visual-c-2008

I recommend switching to MINGW and a different IDE like CodeBlocks http://www.codeblocks.org/, more specifially http://www.codeblocks.org/downloads/26. 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: http://support.microsoft.com/kb/980263.

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.

visual00
Member #15,194
June 2013

wow!

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

beoran
Member #12,636
March 2011

You are welcome. :)

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

Slaweek Shpachenko
Member #15,221
July 2013
avatar

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):

#SelectExpand
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ль"
{"name":"607775","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/6\/36dfd2e43de603d643aa6eca770d2903.png","w":508,"h":129,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/6\/36dfd2e43de603d643aa6eca770d2903"}607775

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.

beoran
Member #12,636
March 2011

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.

Go to: