Loading a SVG File?

Hello, I'm a complete newbie with game programming and the allegro library so please be merciful. Anyways I have been trying to use al_load_bitmap to load my file. Solutions I have tried include initializing the image addon through al_init_image_addon() and specifying the directory(which I am not completely sure that I did correctly). Please advise!

Tobias Dammers

SVG is not a bitmap format, and allegro doesn't support it out-of-the box.

If you want to use SVG, you'll need to use an SVG rendering library (you could write your own, but SVG is pretty complex, so it's probably way over your head), and write some glue to make it render to allegro surfaces.

An easier route is to just open the SVG in the editor of your choice (e.g. Inkscape) and export it to a bitmap format that allegro understands. If you're using A5, I'd recommend PNG - it offers lossless compression, and it supports full truecolor with alpha transparency.

Matthew Leverton
the manual said:

The following types are built into the Allegro image addon and guaranteed to be available: BMP, PCX, TGA. Every platform also supports JPEG and PNG via external dependencies.

SVG isn't on the list, and is not likely to be supported by the OS.


thanks, that clears up alot! I have converted my SVG to a PNG, how do I know which directory allegro looks in for the png?

Edgar Reynaldo

Generally, the current working directory is wherever the program was executed from. You can get the current directory with al_get_current_directory and change it with al_change_directory. I thought there was some way to get the path of the executable but I can't seem to find it right now. This is in Allegro 5 if you were wondering.

Matthew Leverton
Murlocks said:

I have converted my SVG to a PNG, how do I know which directory allegro looks in for the png?

By default, it will be the current working directory, whatever that is. Sometimes that is what you want.

If you know the data is bundled with your project in a folder named data, you should use something like:

ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
al_append_path_component(path, "data");

al_set_path_filename(path, "foo.png");
bmp = al_load_bitmap(al_path_cstr(path, '/'));

Alternatively, you could use al_change_directory() after getting the folder name and then load the image as a relative path (e.g. al_load_bitmap("foo.png")).

The purpose of ALLEGRO_RESOURCES_PATH is that it is cross platform. e.g., On a OS X bundle, data isn't stored directly next to the exe.


Thanks for the responses!

@Edgar: Thank you for that function! That clears up alot in figuring out which directory I was working in.

@Matthew: I really like your proposed idea and I'm trying to get it to work, because I would rather have all my resource files organized in a folder than in the directory of my project. I've tried setting it directly with the path var and changing the current directory to the data folder and proceeding calling the file directly but neither work. Any idea why?

EDIT: Got it working! Any tips on animating PNGs?

Matthew Leverton

Make sure the value of al_path_cstr(path, '/') is what you expect. If using an IDE, you may need to adjust the place where it puts your executable.


yeah I figured out that the problem was that the data folder was in the wrong place, yet /data was still being written into the path var. So when I tried to change the current directory to path, it would fail and nothing would happen because there was no /data folder even though path had it written.

Any tips on animating something like this? http://www.openclipart.org/image/800px/svg_to_png/pacman.png Would I have to include any extra sprite models or is that all I need? (Thinking maybe a closed mouth model for pacman is necessary?) Thanks again for your help!


For something pre-redendered like that you'll need more sprites, Pac-man with mouth closed at the bare minimum. You may even need a few "in between" frames for the motion.

Thread #606474. Printed from Allegro.cc