【问题标题】:Allegro5 cannot decode png images on Ubuntu 20.04 (using cmake)Allegro5 无法在 Ubuntu 20.04 上解码 png 图像(使用 cmake)
【发布时间】:2021-08-15 23:40:18
【问题描述】:

Allegro5 似乎无法为我的游戏项目解码 png 图像。这个函数:

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;
}

返回 NULL。我知道图像路径是正确的,因为相同的代码适用于 Windows。

与本题相关:here

我在 Ubuntu 20.04 中使用预编译的 allegro 5.2.7 包也遇到了同样的问题!我将png 添加为项目的外部库。我的系统中确实安装了 libpng16-16 和 libpng-dev,但是 allegro 似乎无法解码 png 图像!

这是cmake顺便生成的命令,链接中好像包含了libpng:

/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

我想知道我在这里做错了什么。这在 Windows 上开箱即用。

【问题讨论】:

    标签: c++ ubuntu-20.04 libpng allegro5


    【解决方案1】:

    我想我知道答案了!

    执行时路径完全错误:

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

    这是建立一个反斜杠路径。 Linux/Mac 找不到这个文件。当我更正这条路径时,应用程序工作了!

    【讨论】:

      猜你喜欢
      • 2014-05-27
      • 2020-10-03
      • 2021-05-24
      • 2021-11-28
      • 2022-08-17
      • 2021-10-29
      • 2019-03-19
      • 2021-08-13
      • 2020-11-28
      相关资源
      最近更新 更多