Allegro.cc - Online Community

Allegro.cc Forums » Installation, Setup & Configuration » Problems with ttf and font addons

This thread is locked; no one can reply to it. rss feed Print
Problems with ttf and font addons
felipe fujioa
Member #12,695
March 2011

Hi,

i'm new to allegro 5 and i'm having some problems to add text to my program.

There is the part of mt code that is using the allegro addons:

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_font.h> 3#include <allegro5/allegro_ttf.h> 4 5... 6int main(void){ 7al_init(); 8... 9ALLEGRO_FONT *font = NULL; 10 11 al_init_font_addon(); // initialize the font addon 12 al_init_ttf_addon(); 13 14 font = al_load_ttf_font("automati.ttf",72,0 ); 15 16... 17}

when i compile it returns this weird mistakes:

#SelectExpand
1/home/aural/Desktop/JUN/Wiimba_1.0/wmdemo/Wiimba_03.c:601: undefined reference to `al_init_font_addon' 2/home/aural/Desktop/JUN/Wiimba_1.0/wmdemo/Wiimba_03.c:602: undefined reference to `al_init_ttf_addon' 3/home/aural/Desktop/JUN/Wiimba_1.0/wmdemo/Wiimba_03.c:604: undefined reference to `al_load_ttf_font'

Ive already done some programs with allegro5, but qhen i tried the addons it did not compiled.

I looked into the libraries of the allegro folder, but did not find any reference to the allegro_ttf.h. Do i have to download it separately?

Could someone help me?

jmasterx
Member #11,410
October 2009

You might be missing FreeType or another dependency, what did cmake say you were missing?

Matthew Leverton
Supreme Loser
January 1999
avatar

You need to link with the addon libraries.

felipe fujioa
Member #12,695
March 2011

i think i partially solved the problem. I linked the libraries, but now the gcc accuses a lot of error in the allegro_font.h.

for example:

#SelectExpand
1... 2allegro_font.h:59: error: ‘font_height’ has not been declared 3allegro_font.h:59: error: expected identifier before ‘(’ token 4allegro_font.h:59: error: ISO C++ forbids declaration of ‘AL_METHOD’ with no type 5allegro_font.h:60: error: ‘font_ascent’ has not been declared 6...

someone know what is wrong?

Thomas Fjellstrom
Member #476
June 2000
avatar

You just need to link to the addon libraries, similar to how you link to the allegro library itself.

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

felipe fujioa
Member #12,695
March 2011

Well, i linked it.

But the strange problems i said before happened.

Thomas Fjellstrom
Member #476
June 2000
avatar

Are you including allegro_font.h before or after allegro5.h?

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

felipe fujioa
Member #12,695
March 2011

after, does it make any diference?

from my make file

LIB = serial.c CreateControl.c Getch.c CreateMath.c LibGa.c allegro5.h allegro.h allegro_font.h allegro_ttf.h font.h

but the compiler is accusing errors in the library. =/

Thomas Fjellstrom
Member #476
June 2000
avatar

LIB = serial.c CreateControl.c Getch.c CreateMath.c LibGa.c allegro5.h allegro.h allegro_font.h allegro_ttf.h font.h

Don't do that. You don't want to compile headers. You need to #include <headernamehere> them in your source (.c) files.

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

felipe fujioa
Member #12,695
March 2011

I'm including the libraries on my ~.c file, and they are after allegro5.h.

but when i try to compile gcc accuses al_init_font_addon() and al_init_ttf_addon() not to be defined.

Thomas Fjellstrom
Member #476
June 2000
avatar

ut when i try to compile gcc accuses al_init_font_addon() and al_init_ttf_addon() not to be defined.

Please show how you're compiling, and your source file that uses those functions.

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

felipe fujioa
Member #12,695
March 2011

This is the part of the code i'm trying to use allegro font and ttf addons.

#SelectExpand
1#include <stdio.h> 2... 3#include <allegro5/allegro.h> 4#include <allegro5/allegro5.h> 5#include <allegro5/allegro_font.h> 6#include <allegro5/allegro_ttf.h> 7... 8int posx1 = 200; 9 int posy1 = 200; 10 int posx2 = 200; 11 int posy2 = 200; 12 int BOUNCER_SIZE = 10; 13 int FPS = 60; 14 15 bool key[4] = { false, false, false, false }; 16 bool doexit = false; 17 18 ALLEGRO_DISPLAY *display = NULL; 19 ALLEGRO_BITMAP *bouncer = NULL; 20 ALLEGRO_BITMAP *bouncer2 = NULL; 21 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 22 ALLEGRO_TIMER *timer = NULL; 23 ALLEGRO_FONT *font = NULL; 24 25 al_init_font_addon(); // initialize the font addon 26 al_init_ttf_addon(); 27 28 font = al_load_ttf_font("automati.ttf",72,0 ); 29 30 if(!al_init()) { 31 fprintf(stderr, "failed to initialize allegro!\n"); 32 return -1; 33 } 34 35 timer = al_create_timer(1.0 / FPS); 36 if(!timer) { 37 fprintf(stderr, "failed to create timer!\n"); 38 return -1; 39 } 40 41 if(!al_install_keyboard()) { 42 fprintf(stderr, "failed to initialize the keyboard!\n"); 43 return -1; 44 } 45 46 display = al_create_display(1024, 512); 47 if(!display) { 48 fprintf(stderr, "failed to create display!\n"); 49 return -1; 50 } 51 52 bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE); 53 if(!bouncer) { 54 fprintf(stderr, "failed to create bouncer bitmap!\n"); 55 al_destroy_display(display); 56 return -1; 57 } 58 59 bouncer2 = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE); 60 if(!bouncer2) { 61 fprintf(stderr, "failed to create bouncer bitmap!\n"); 62 al_destroy_display(display); 63 return -1; 64 } 65 66 event_queue = al_create_event_queue(); 67 if(!event_queue) { 68 fprintf(stderr, "failed to create event_queue!\n"); 69 al_destroy_bitmap(bouncer); 70 al_destroy_display(display); 71 al_destroy_timer(timer); 72 return -1; 73 } 74 75 76 al_set_target_bitmap(bouncer); 77 78 al_clear_to_color(al_map_rgb(255,0,255)); 79 80 al_set_target_bitmap(bouncer2); 81 82 al_clear_to_color(al_map_rgb(0,255,255)); 83 84 al_set_target_bitmap(al_get_backbuffer(display)); 85 86 al_register_event_source(event_queue, al_get_display_event_source(display)); 87 88 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 89 90 al_register_event_source(event_queue, al_get_keyboard_event_source()); 91 92 93 al_start_timer(timer); 94 95 96 while(!doexit){ 97 98 ALLEGRO_EVENT ev; 99 al_wait_for_event(event_queue, &ev); 100 101 if (cwiid_get_state(wiimote, &state)) { //Atualiza estado 102 fprintf(stderr, "Error getting state\n"); 103 } 104 botao = button_state(&state); 105 106 107 for (i = 0; i < CWIID_IR_SRC_COUNT; i++) { //CWIID_IR_SRC_COUNT guarda a quantidade de pontos(IR) validos encontrados pelo controle 108 if (state.ir_src[i].valid) { //verifica a validade do ponto 109 valid_source = 1; 110 posx1 = state.ir_src[0].pos[CWIID_X]; 111 posy1 = state.ir_src[0].pos[CWIID_Y]; 112 posx2 = state.ir_src[1].pos[CWIID_X]; 113 posy2 = state.ir_src[1].pos[CWIID_Y]; 114 115 } 116 } 117 118 if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 119 break; 120 }else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { 121 switch(ev.keyboard.keycode) { 122 case ALLEGRO_KEY_UP: 123 key[KEY_UP] = true; 124 break; 125 126 case ALLEGRO_KEY_DOWN: 127 key[KEY_DOWN] = true; 128 break; 129 130 case ALLEGRO_KEY_LEFT: 131 key[KEY_LEFT] = true; 132 break; 133 134 case ALLEGRO_KEY_RIGHT: 135 key[KEY_RIGHT] = true; 136 break; 137 } 138 } 139 else if(ev.type == ALLEGRO_EVENT_KEY_UP) { 140 switch(ev.keyboard.keycode) { 141 case ALLEGRO_KEY_UP: 142 key[KEY_UP] = false; 143 break; 144 145 case ALLEGRO_KEY_DOWN: 146 key[KEY_DOWN] = false; 147 break; 148 149 case ALLEGRO_KEY_LEFT: 150 key[KEY_LEFT] = false; 151 break; 152 153 case ALLEGRO_KEY_RIGHT: 154 key[KEY_RIGHT] = false; 155 break; 156 157 case ALLEGRO_KEY_ESCAPE: 158 doexit = true; 159 break; 160 } 161 } 162 163 164 if(key[KEY_UP]) 165 al_clear_to_color(al_map_rgb(0,0,0)); 166 167 al_draw_bitmap(bouncer, posx1, posy1, 0); 168 169 al_draw_bitmap(bouncer, posx2, posy2, 0); 170 171 al_flip_display(); 172 173 174 } 175 176 177 al_destroy_display(display); 178 179 180 181 182 if(botao & bHome) exit = 0;

this is my Makefile.

#SelectExpand
1 2include defs.mak 3 4CXX = g++ 5 6LIB = serial.c CreateControl.c Getch.c CreateMath.c LibGa.c allegro5.h allegro.h 7 8CFLAGS += -I../libcwiid -g -Wall -I/addons/font -I/addons/ttf 9LDFLAGS += -L../libcwiid -L/addons/font -L/addons/ttf 10LDLIBS += -lcwiid 11INST_DIR = ${exec_prefix}/bin 12 13 14Wiimba: Wiimba_03.o 15 $(CXX) $(CFLAGS) $(LDLIBS) $(LIB) -o $@ $< -lgcc -lm -lncurses `pkg-config --libs allegro-5.0` 16 17Wiimba_03.o: Wiimba_03.c 18 $(CXX) $(CFLAGS) -c -o $@ $< 19 20 21 22 23 24clean: clean 25 rm Wiimba 26 27.PHONY: distclean

and the error is that the compiler do not find the definitions to al_init_font_addon; al_init_ttf addon and al_load_ttf_font("automati.ttf",72,0 ).

the full compiling log

#SelectExpand
1 2g++ -g -Wall -W -DHAVE_CONFIG_H -I../common/include -I../libcwiid -g -Wall -I/addons/font -I/addons/ttf -c -o Wiimba_03.o Wiimba_03.c 3Wiimba_03.c:334:4: warning: "/*" within comment 4Wiimba_03.c: In function ‘int main(int, char**): 5Wiimba_03.c:785: warning: suggest parentheses around assignment used as truth value 6Wiimba_03.c:285: warning: unused variable ‘mesg’ 7Wiimba_03.c:288: warning: unused variable ‘rumble’ 8Wiimba_03.c: At global scope: 9Wiimba_03.c:1054: warning: unused parameter ‘timestamp’ 10g++ -g -Wall -W -DHAVE_CONFIG_H -I../common/include -I../libcwiid -g -Wall -I/addons/font -I/addons/ttf -lcwiid serial.c CreateControl.c Getch.c CreateMath.c LibGa.c allegro5.h allegro.h -o Wiimba Wiimba_03.o -lgcc -lm -lncurses `pkg-config --libs allegro-5.0` 11Wiimba_03.o: In function `main': 12/home/aural/Desktop/JUN/Wiimba_1.1/wmdemo/Wiimba_03.c:602: undefined reference to `al_init_font_addon' 13/home/aural/Desktop/JUN/Wiimba_1.1/wmdemo/Wiimba_03.c:603: undefined reference to `al_init_ttf_addon' 14/home/aural/Desktop/JUN/Wiimba_1.1/wmdemo/Wiimba_03.c:605: undefined reference to `al_load_ttf_font' 15collect2: ld returned 1 exit status 16make: *** [Wiimba] Error 1

Arthur Kalliokoski
Second in Command
February 2005
avatar

Try:

`pkg-config --libs allegro-5.0 allegro_ttf-5.0`

If that's not enough: (from one of my makefiles)

`pkg-config --libs allegro-5.0 allegro_ttf-5.0 allegro_image-5.0 allegro_primitives-5.0`

They all watch too much MSNBC... they get ideas.

Evert
Member #794
November 2000
avatar

g++ -g -Wall -W -DHAVE_CONFIG_H -I../common/include -I../libcwiid -g -Wall -I/addons/font -I/addons/ttf -lcwiid serial.c CreateControl.c Getch.c CreateMath.c LibGa.c allegro5.h allegro.h -o Wiimba Wiimba_03.o -lgcc -lm -lncurses `pkg-config --libs allegro-5.0`

Don't link with header files. You #include them in your source code to make declarations in them visible to functions within that source file.

As pointed out here.

felipe fujioa
Member #12,695
March 2011

Thank you,

the Arthur Kalliokoski's solution worked.

Perhaps, i'm having problems to load a ttf file. The ttf is in the same directory as my ~.c file and executable. But when it try to load, it gets a segfault.

Just to have my font file in the same directory should work? Or i have to do any configuration, or add any library?

=)

Arthur Kalliokoski
Second in Command
February 2005
avatar

They all watch too much MSNBC... they get ideas.

felipe fujioa
Member #12,695
March 2011

Thx,

but my ttf file is not even loading. It get a seg fault and returns nothing.

Arthur Kalliokoski
Second in Command
February 2005
avatar

In other words, you're already doing

 font = al_load_ttf_font("automati.ttf",72,0 );
 if(!font)
 {
    some_error_msg();
    exit(1);
 }

I've had it crash so bad it locked up the entire machine if the font was big enough with a point size 200+. (?) It was crashing the display driver.

They all watch too much MSNBC... they get ideas.

felipe fujioa
Member #12,695
March 2011

Yes, i've already done that.

but when i reach the part of the code that uses the ttf loading, it Segfaults =\

Could it be a problem with the *.ttf font? Any ideas?

I've tried this as well:

#SelectExpand
1 2ALLEGRO_PATH *p = al_get_standard_path(ALLEGRO_RESOURCES_PATH); 3 4 const char *c = al_path_cstr(p, ALLEGRO_NATIVE_PATH_SEP ); 5 6 al_change_directory("/home/jun/Desktop/CTI/Wiimba_1.1/wmdemo"); 7 8 font = al_load_ttf_font("/home/jun/Desktop/CTI/Wiimba_1.1/wmdemo/automati.ttf",30, 0 );

and got:

#SelectExpand
1 2Wiimba: /home/jun/Downloads/allegro-5.0.0/src/system.c:346: al_get_standard_path: Assertion `active_sysdrv' failed. 3

i'm using ubuntu 10.10.

Thx

Go to: