|
Routes with allegro problem |
Angoll
Member #12,852
May 2011
|
Hi, thaks for advance I try to open a .ttf file I try to do: ALLEGRO_FONT *font = al_load_ttf_font("font.ttf",12,0 ); But that way search the "font.ttf" in my user path, and not the path I have the program. So I try to do: 1int Ini_fonts(ALLEGRO_FONT **font_2)
2{ al_init_font_addon();
3 al_init_ttf_addon();
4 ALLEGRO_PATH *path;
5 char *path_cstr;
6 path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
7 al_set_path_filename(path, "font");
8 al_set_path_extension(path, ".ttf");
9 path_cstr = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);
10 al_destroy_path(path);
11 ALLEGRO_FONT *font = al_load_ttf_font(path_cstr,12,0 );
12 *font_2 = font;
13 return 0;
14}
15
16void funcion()
17{
18 ALLEGRO_FONT *font;
19 Ini_fonts(&font);
20 al_draw_text(font, al_map_rgb(red_ttf,blue_ttf,green_ttf), text1_pos_x, text1_pos_y,text_allign, "text");
21 al_flip_display();
22 al_destroy_font(font);
23 al_shutdown_ttf_addon();
24 al_shutdown_font_addon();
25}
26
27
28int main(int argc,char **argv)
29{
30 ALLEGRO_DISPLAY *display;
31 if(!al_init()) {
32 fprintf(stderr, "failed to initialize allegro!\n");
33 return -1;}
34 display = al_create_display(SCREEN_W, SCREEN_H);
35 if(!display) {
36 fprintf(stderr, "failed to create display!\n");
37 return -1;}
38 al_clear_to_color(al_map_rgb(0,0,0));
39 al_flip_display();
40 //---------
41 // HERE
42 funcion();
43
44 al_clear_to_color(al_map_rgb(0,0,0));
45 al_flip_display();
46
47 //----------
48 // HERE
49 funcion();
50
51 al_destroy_display(display)
52 return 0;
53}
the first time I call funcion() goes well, but de second goes wrong I try to do this step by step and I think the problem is this line: Quote: path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); Maybe I have to do it a diferent way, because here I'm using absolute path, I prefer know to how use relative path but I dont know how implement this I try to run the same code with out using all the Path's things and it's works but my .ttf has to be in my local path. :/ thanks, if you dont understand some think ask please
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
First off, decide where you are going to keep your font - ie. : If you are always going to have font.ttf in the same directory as your program, then use ALLEGRO_EXENAME_PATH as the id to al_get_standard_path. 1void FixDirectory() {
2 ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_EXENAME_PATH);
3 al_set_path_filename(path , "");
4 al_set_path_extension(path , "");
5 const char* cstr = al_path_cstr(path , ALLEGRO_NATIVE_PATH_SEP);
6 al_change_directory(cstr);
7 al_destroy_path(path);
8}
9
10// in main
11init();
12FixDirectory();
13ALLEGRO_FONT* font = al_load_font("font.ttf" , 12 , 0);
14if (!font) {return 1;}
15// use font normally
Angoll said: the first time I call funcion() goes well, but de second goes wrong I try to do this step by step and I think the problem is this line: It doesn't work the second time because it calls al_shutdown_ttf_addon and al_shutdown_font_addon the first time it is called, so loading fonts will no longer work. You don't need to call any shutdown functions directly, as Allegro will do it for you. You're only responsible for destroying any objects you create. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|