Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » [A5] File exists, but won't load

Credits go to Mark Oates for helping out!
This thread is locked; no one can reply to it. rss feed Print
[A5] File exists, but won't load
Onewing
Member #6,152
August 2005
avatar

I've run into a roadblock trying to get the basics of A5 going. I've determined a file exits via al_filename_exists, but al_load_bitmap continues to fail for reasons I can't seem to debug. My code is basically a mash of wiki tutorial code (doing speedhack '15). Scroll to "Test Grounds..." comment for relevant code:

#SelectExpand
1#include <stdio.h> 2#include <allegro5/allegro.h> 3#include "allegro5/allegro_image.h" 4#include "allegro5/allegro_native_dialog.h" 5 6const float FPS = 60; 7const int SCREEN_W = 640; 8const int SCREEN_H = 480; 9const int BOUNCER_SIZE = 32; 10 11int main(int argc, char **argv){ 12 ALLEGRO_DISPLAY *display = NULL; 13 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 14 ALLEGRO_TIMER *timer = NULL; 15 ALLEGRO_BITMAP *bouncer = NULL; 16 float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0; 17 float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0; 18 float bouncer_dx = -4.0, bouncer_dy = 4.0; 19 bool redraw = true; 20 21 if(!al_init()) { 22 fprintf(stderr, "failed to initialize allegro!\n"); 23 return -1; 24 } 25 26 timer = al_create_timer(1.0 / FPS); 27 if(!timer) { 28 fprintf(stderr, "failed to create timer!\n"); 29 return -1; 30 } 31 32 display = al_create_display(SCREEN_W, SCREEN_H); 33 if(!display) { 34 fprintf(stderr, "failed to create display!\n"); 35 al_destroy_timer(timer); 36 return -1; 37 } 38 39 bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE); 40 if(!bouncer) { 41 fprintf(stderr, "failed to create bouncer bitmap!\n"); 42 al_destroy_display(display); 43 al_destroy_timer(timer); 44 return -1; 45 } 46 47 al_set_target_bitmap(bouncer); 48 49 al_clear_to_color(al_map_rgb(255, 0, 255)); 50 51 al_set_target_bitmap(al_get_backbuffer(display)); 52 53 event_queue = al_create_event_queue(); 54 if(!event_queue) { 55 fprintf(stderr, "failed to create event_queue!\n"); 56 al_destroy_bitmap(bouncer); 57 al_destroy_display(display); 58 al_destroy_timer(timer); 59 return -1; 60 } 61 62 al_register_event_source(event_queue, al_get_display_event_source(display)); 63 64 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 65 66 al_clear_to_color(al_map_rgb(0,0,0)); 67 68 al_flip_display(); 69 70 al_start_timer(timer); 71 72 73 /// Test Grounds... 74 ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); 75 al_append_path_component(path, "Resources"); 76 al_set_path_filename(path, "test2.png"); 77 const char *test = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP); 78 const char *test2 = al_path_cstr(path, '/'); 79 if(al_filename_exists(test2)) { 80 fprintf(stderr, "hello world\n"); 81 } 82 83 fprintf(stderr, "%s\n", test2); 84 ALLEGRO_BITMAP *image = al_load_bitmap(test2); 85 86 if(!image) { 87 al_show_native_message_box(display, "Error", "Error", "Failed to load image!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 88 al_destroy_display(display); 89 return 0; 90 } 91 92 al_draw_bitmap(image,200,200,0); 93...

The output I get is the following:
hello world
/Users/UserName/Library/Developer/Xcode/DerivedData/eldersofethos-fvfhklodylcqfegmldyrzbooqcre/Build/Products/Debug/EldersOfEthos.app/Contents/Resources/Resources/test2.png

Thoughts?

Edit: attached the image.

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Mark Oates
Member #1,146
March 2001
avatar

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Onewing
Member #6,152
August 2005
avatar

Bingo.

The manual says: "You must use the allegro_image addon, or register your own format handler."

I thought that meant simply including "allegro5/allegro_image.h", but now I see in the tutorial the following code that I overlooked:

#SelectExpand
1if(!al_init_image_addon()) { 2 al_show_native_message_box(display, "Error", "Error", "Failed to initialize al_init_image_addon!", 3 NULL, ALLEGRO_MESSAGEBOX_ERROR); 4 return 0; 5 }

Thank you, sir!

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Mark Oates
Member #1,146
March 2001
avatar

No prob. You can do it! :D

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Go to: