Allegro5 cannot decode png images on Ubuntu 20.04 (using cmake)

83 Views Asked by At

Allegro5 cannot seem to be able to decode png images for my game project. This function:

ALLEGRO_BITMAP* BrushCollection::LoadBitmapFromFile(const char* fileName)
{
    ALLEGRO_PATH* path = al_get_standard_path(ALLEGRO_EXENAME_PATH);

    al_append_path_component(path, "assets");
    al_set_path_filename(path, fileName);

    ALLEGRO_BITMAP* bitmap = al_load_bitmap(al_path_cstr(path, '\\'));
    allegro_init(bitmap, L"UI Bitmap");

    return bitmap;
}

returns NULL. I know image paths are correct because the same code works on Windows.

Related to this question: here

I'm having this same issue in Ubuntu 20.04 with the precompiled allegro 5.2.7 package! I added png as an external library to the project. I do have libpng16-16 and libpng-dev installed in my system, but allegro can't seem to be able to decode png images!

This is the command generated by cmake by the way, which seems to be including libpng in the linking:

/usr/bin/c++  -g   CMakeFiles/Planetaire.dir/src/main.cpp.o CMakeFiles/Planetaire.dir/src/Game.cpp.o CMakeFiles/Planetaire.dir/src/brush/BrushCollection.cpp.o CMakeFiles/Planetaire.dir/src/events/EventStack.cpp.o CMakeFiles/Planetaire.dir/src/events/MouseEvents.cpp.o CMakeFiles/Planetaire.dir/src/text/FontCollection.cpp.o CMakeFiles/Planetaire.dir/src/tools/AllegroInit.cpp.o CMakeFiles/Planetaire.dir/src/tools/Debug.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/ContinueGame.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/HideInGameMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/HideMainMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/QuitGame.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/QuitToDesktop.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/ShowInGameMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/ShowMainMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/actions/StartNewGame.cpp.o CMakeFiles/Planetaire.dir/src/ui/components/AbstractComponent.cpp.o CMakeFiles/Planetaire.dir/src/ui/components/InGameMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/components/MainMenu.cpp.o CMakeFiles/Planetaire.dir/src/ui/AbstractUIElement.cpp.o CMakeFiles/Planetaire.dir/src/ui/ButtonElement.cpp.o CMakeFiles/Planetaire.dir/src/ui/ImageElement.cpp.o CMakeFiles/Planetaire.dir/src/ui/MainUIElement.cpp.o CMakeFiles/Planetaire.dir/src/ui/PanelElement.cpp.o CMakeFiles/Planetaire.dir/src/world-generator/Terrain.cpp.o  -o Planetaire  -lallegro -lallegro_main -lallegro_font -lallegro_ttf -lallegro_image -lallegro_primitives /usr/lib/x86_64-linux-gnu/libpng.so

I wonder what I'm doing wrong here. This works out of the box on windows.

1

There are 1 best solutions below

0
Matias Jose On

I think I know the answer!

The path is simply wrong, when doing:

    ALLEGRO_BITMAP* bitmap = al_load_bitmap(al_path_cstr(path, '\\'));

This is building a backward slash path. Linux/Mac can't find this file. When I corrected this path, the application worked!