SFML无法从图像文件夹加载纹理 - 无法打开文件

问题描述 投票:0回答:1
从文件images/board.png和images/figures.png.

加载纹理。

什么有效:

I使用

std::filesystem::current_path()

检查了工作目录,并指向正确的位置:

C:/Users/Ola/Desktop/Studia/c++/Szachy/x64/Debug

。 图像文件夹中存在纹理文件。

void ChessGame::loadTextures() { if (!boardTexture.loadFromFile("images/board.png")) { std::cerr << "Failed to load board texture (images/board.png)" << std::endl; } if (!pieceTexture.loadFromFile("images/figures.png")) { std::cerr << "Failed to load piece textures (images/figures.png)" << std::endl; } boardSprite.setTexture(boardTexture); for (int i = 0; i < 32; i++) { pieces[i].setTexture(pieceTexture); } }

folder结构:
x64
└── Debug
    ├── Szachy.exe
    ├── images
    │   ├── board.png
    │   └── figures.png
控制台中的eRROR消息:

Failed to load image "". Reason: Unable to open file
Failed to load board texture
Failed to load piece textures

可能导致这个问题,我该如何解决?

当您最终将一个空字符串或随机字符作为错误消息中的路径时,通常是运行时兼容性损坏的指示。

大多数情况下,人们以调试模式链接SFML发布库,或以发行模式链接debug库,因此最终以其应用程序代码和SFML之间的不同,不兼容的运行时间。

确保您仅在调试模式配置中将库文件与
-d
后缀链接,而在发行模式下没有后缀。

注:如果您使用静态库,则后缀为debug,并且with worizeworree

c++ sfml relative-path
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.