Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro in the file management.

This thread is locked; no one can reply to it. rss feed Print
Allegro in the file management.
keprast
Member #16,794
January 2018

Not quite understand how the location of resource files (such as pictures) is expressed?
For example: c / abc / img00.png and c / abc / img01.png
These two pictures in the same folder, but the citation is the time to write it?
c / abc

binary_brain
Member #16,810
February 2018

// variable initialization
ALLEGRO_PATH *path;
ALLEGRO_BITMAP *image;

// get location of
path = al_get_standard_path ( ALLEGRO_RESOURCES_PATH ); // get location of your executable
al_append_path_component ( path, "img" ); // the folder containing your images
al_set_path_filename ( path, "image.png" ); // set the image name
image = al_load_bitmap ( al_path_cstr (path, ALLEGRO_NATIVE_PATH_SEP) );

// if you have only one image you can write as well (before al_load_bitmap)
al_set_path_filename ( path, "img/image.png" );

keprast
Member #16,794
January 2018

@binary_brain

Thanks! :D
However, the executable file location, do not need to set it?(.exe?.cpp?)

For example, I have a picture in c / abc, I need to set the file path to:
al_append_path_component (path, "c/abc");
or
only one:
al_set_path_filename ( path, "c/abc/image.png" );

Is that right?

binary_brain
Member #16,810
February 2018

I don't really know what do you mean. However:

- you need the location of exacutable if you run your executable from another location than you're currently in. Providing that you have a folder "./docs/c/games/_your_game_/_your_executable_" than if you will be in your_game folder the default location will be the same as the location of executable - "./img/_some_img_" will become "./docs/c/games/_your_game_/img/_some_img_", but if you were in ex. "games" folder your images simply won't load.

- al_set_path_filename ( path, "img/image.png" ) is kind of a trick and I cannot grant you that it will work on any supported OS.
It works simply because al_path_cstr will replace filename with directory and filename (it produces a simple char * (string)). However it is by no means recommended solution.

Audric
Member #907
January 2001

bb's code is what you need when the game file are stored like :
c:\projects\mygame\ mygame.exe
c:\projects\mygame\ img\image.png

(Here's the same code he posted, formatted for line numbers)

#SelectExpand
1// variable initialization 2ALLEGRO_PATH *path; 3ALLEGRO_BITMAP *image; 4 5// get location of 6path = al_get_standard_path ( ALLEGRO_RESOURCES_PATH ); // get location of your executable 7al_append_path_component ( path, "img" ); // the folder containing your images 8al_set_path_filename ( path, "image.png" ); // set the image name 9image = al_load_bitmap ( al_path_cstr (path, ALLEGRO_NATIVE_PATH_SEP) ); 10 11// if you have only one image you can write as well (before al_load_bitmap) 12al_set_path_filename ( path, "img/image.png" );

Beginning : path is an empty path
Line 6 : path is C:\projects\mygame\mygame.exe
Line 7 : path is C:\projects\mygame\ img\mygame.exe
Line 8 : path is c:\projects\mygame\img\ image.png

Line 12 is a way to combine line 7 and 8, but it only works is path is the "root" of your game. Otherwise, it will create paths like "img/img/img"...

keprast
Member #16,794
January 2018

So this is, I understand.
thank you for the help.

Go to: