C++ SFML 2.0 从文件加载图像
C++ SFML 2.0 Load Image From File
我是SFML的新手,我正在使用SFML 2.0,我只是写了一些代码,它的工作正常,但问题是我加载图像以显示在屏幕上,它给了我错误
Failed to load image "Splashscreen.png". Reason : Unable to open file
Failed to load image "Mainmenu.png". Reason : Unable to open file
我从 URL 加载图像的代码是
对于菜单图像
sf::Texture menuTexture;
menuTexture.loadFromFile("Mainmenu.png");
{
sf::Sprite sprite(menuTexture);
MenuItem playButton;
playButton.rect.top = 145;
playButton.rect.height = playButton.rect.top + 380;
playButton.rect.left = 0;
playButton.rect.width = playButton.rect.left + 1023;
playButton.menuAction = Play;
MenuItem exitButton;
exitButton.rect.top = 0;
exitButton.rect.height = exitButton.rect.top + 1023;
exitButton.rect.left = 383;
exitButton.rect.width = exitButton.rect.left + 560;
exitButton.menuAction = Exit;
menuItem.push_back(playButton);
menuItem.push_back(exitButton);
window.draw(sprite);
window.display();
return GetMenuResponse(window);
}
对于初始屏幕图像
sf::Texture texture;
if(texture.loadFromFile("Splashscreen.png") != true)
{
return;
}
sf::Sprite sprite(texture);
renderWindow.clear();
renderWindow.draw(sprite,sf::RenderStates::Default);
renderWindow.display();
sf::Event event;
while(true)
{
while(renderWindow.pollEvent(event))
{
if(event.type == sf::Event::EventType::KeyPressed
|| event.type == sf::Event::EventType::MouseButtonPressed
|| event.type == sf::Event::EventType::Closed)
{
return;
}
}
}
图像未加载,任何人都可以帮助解决此问题。
但是当我构建我的项目并从调试文件夹运行相同的程序时,我的意思是当我运行exe文件图像时,图像显示出来,但是当我从Visual Studio 2010运行程序时,图像没有加载当我在发布模式下运行程序时,程序崩溃了。
您是否检查过该文件是否在您的工作目录中?它可以与输出目录不同!
相关文章:
- 将 bmp 文件加载到 TSpeedButton 中
- 如何将文本文件加载到 QListwidget 并将其保存回来
- 从 C 可执行文件加载动态库时收到错误C++"undefined symbol"
- 优化从文件加载QImage
- 将csv文件加载到MySQL C++中
- 从文件加载结构
- 如何在 QT 中显示文件加载状态
- C++ 如何从文件加载异类集合
- 从文本文件加载链表并打印时无限循环
- Kotlin 从文件加载类的集合?
- 如何从文件加载QJsonDocument
- SFML 将图像从 txt 文件加载到矢量中仅加载最后一个图像
- 使用ifstream从DAT文件加载数据
- 从 C 中的文件加载结构时出现分段错误
- 从二进制文件加载列表后,我的代码似乎进入了无限循环
- Qml:从文件加载组件时将参数作为 URL 的一部分传递
- 将浮点数保存在文本文件中,然后从文本文件加载回去(OpenGL和C++)
- 从TXT文件加载迷宫
- 从文件加载uint64_t值
- 如何在 c++ 中将二进制文件加载/读取到"vector<vector< bitset<32> >"中?