Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » images dont load [a5]

This thread is locked; no one can reply to it. rss feed Print
images dont load [a5]
shadyvillian
Member #12,426
December 2010

I made a simple that loads and displays an image. at my house every thing worked ok. then when I bring it to school the image wont load(i have error checking after and it returns 1 if the file is still null.) it returns 1 every time. its the same source file and the image is the same and in the spot in the folder. why do you think it does this?

Software Engineer by day, hacker by night.

LennyLen
Member #5,313
December 2004
avatar

What size is the image? It may be too large for the school computer's GPU to be able to handle as a texture. If so, you can always try loading it as a memory bitmap rather than as a video bitmap.

shadyvillian
Member #12,426
December 2010

How do I load it as a memory bitmap and whats the difference? I think I've heard of it but never used it before.

Software Engineer by day, hacker by night.

William Labbett
Member #4,486
March 2004
avatar

al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);

memory bitmaps are stored in normal RAM

video bitmaps are stored in RAM on the gfx card

Neil Walker
Member #210
April 2000
avatar

Try explicitly stating the path in the load function, it could be a working folder issue, e.g. debug mode.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Matthew Leverton
Supreme Loser
January 1999
avatar

How do I load it as a memory bitmap and whats the difference?

Memory bitmaps are slower to use, but can be larger than the default video bitmaps.

Thus, you should try to load images as a regular video bitmap. If a large image fails to load, then you can load it as a memory bitmap instead. But you should detect that at run time, so that better computers will not use memory bitmaps when they could be using hardware accelerated ones.

shadyvillian
Member #12,426
December 2010

I've tried using memory bitmaps, different sized images, different formats and typing out the complete path and still it wont load.

Software Engineer by day, hacker by night.

Neil Walker
Member #210
April 2000
avatar

Post your code with image then.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

shadyvillian
Member #12,426
December 2010

#SelectExpand
1#include <allegro5/allegro.h> 2#include <allegro5/allegro_image.h> 3 4int main() 5{ 6 ALLEGRO_DISPLAY *Screen = NULL; 7 ALLEGRO_BITMAP *Image = NULL; 8 ALLEGRO_EVENT_QUEUE *EventQueue; 9 ALLEGRO_EVENT Event; 10 11 bool Quit = false; 12 13 al_init(); 14 al_init_image_addon(); 15 16 // al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP); 17 18 EventQueue = al_create_event_queue(); 19 20 Screen = al_create_display(800, 600); 21 22 al_register_event_source(EventQueue, al_get_display_event_source(Screen)); 23 24 Image = al_load_bitmap("Media/NextShapeBox.png"); 25 26 if(!Image) 27 { 28 return 1; 29 } 30 31 while(Quit == false) 32 { 33 al_draw_bitmap(Image, 0, 0, 0); 34 35 al_flip_display(); 36 37 al_wait_for_event(EventQueue, &Event); 38 39 if(Event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) 40 { 41 Quit = true; 42 } 43 } 44 45 al_destroy_bitmap(Image); 46 al_destroy_event_queue(EventQueue); 47 48 return 0; 49}

Software Engineer by day, hacker by night.

Thomas Fjellstrom
Member #476
June 2000
avatar

Windows doesn't like to run your executable from the directory you think it should be, so when you try to use a relative path like you are, it will be relative to whatever windows has set as the current working directory, not the one you think it is.

First try using an abosolute path to your files, then play with the al_get_standard_path to locate your 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

shadyvillian
Member #12,426
December 2010

What do i do with al_get_standard_path? al_get_standard_path(ALLEGRO_EXENAME_PATH);?
what would I do with this?

Software Engineer by day, hacker by night.

Matthew Leverton
Supreme Loser
January 1999
avatar

On Windows, make sure the data is stored relative to the exe

ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "Media");
al_set_path_filename(path, "foo.png");

// a hack, but this probably works in place of the 'append':
// al_set_path_filename(path, "Media/foo.png");

al_load_bitmap(al_path_cstr(path, '/'));

The above code assumes the image is in a folder called 'Media' next to the executable. The documentation explains this clearly:

Quote:

If you bundle data in a location relative to your executable, then you should use this path (ALLEGRO_RESOURCES_PATH) to locate that data.

shadyvillian
Member #12,426
December 2010

Oh I see. Just curious why do you consider it a hack?

Software Engineer by day, hacker by night.

Matthew Leverton
Supreme Loser
January 1999
avatar

It's a hack, because you're abusing the structure a bit. An Allegro path is a vector of path components, eg: "usr", "share", "mygame". Then it has a filename: "img.png".

When you call al_path_cstr(), it joins them together with the delimiter you supply.

So if you add something like "foo/bar" via al_append_path_component() or al_set_path_filename(), you are putting two pieces together in a single slot of the vector.

It doesn't really matter in that when you call al_path_cstr() you'll get the same result. However, you cannot traverse each component individually now, since Allegro will treat your "combo" component as a single entity.

I doubt the functionality will ever change, so it should be safe to use.

shadyvillian
Member #12,426
December 2010

Its crashing at path = al_get_standard_path. this must be the universe telling me that this just isn't going to work. Its probably has to do with some sort of restrictions on the computers. looks like I wont be able to show off my programs to people in my programming class :( because I cant even run the exe there because it just closes instantly from the images failing to load.

Software Engineer by day, hacker by night.

Matthew Leverton
Supreme Loser
January 1999
avatar

Make sure you are calling al_init() first.

shadyvillian
Member #12,426
December 2010

I'll double check tomorrow. Its still a pain in the butt to have to do this especially if i have to load like 50 images. Is this standard or something special you do?

Software Engineer by day, hacker by night.

Matthew Leverton
Supreme Loser
January 1999
avatar

You can also do it this way:

ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_change_directory(al_path_cstr(path), '/');
al_destroy_path(path);

foo1 = al_load_bitmap("images/foo1.png");
foo2 = al_load_bitmap("images/foo2.png");

bamccaig
Member #7,536
July 2006
avatar

shadyvillian
Member #12,426
December 2010

It still doesn't work after doing the thing with the paths.

Software Engineer by day, hacker by night.

Go to: