images dont load [a5]
shadyvillian

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?

LennyLen

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

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.

William Labbett

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

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

Matthew Leverton

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

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

Neil Walker

Post your code with image then.

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

Thomas Fjellstrom

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.

shadyvillian

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

Matthew Leverton

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

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

Matthew Leverton

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

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.

Matthew Leverton

Make sure you are calling al_init() first.

shadyvillian

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?

Matthew Leverton

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

It looks like this will be useful to you: http://wiki.allegro.cc/index.php?title=Return_values

shadyvillian

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

Thread #606701. Printed from Allegro.cc