Texture.loadFromFile 不起作用 [英] Texture.loadFromFile doesn't work

查看:78
本文介绍了Texture.loadFromFile 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 SFML 2.2 和 Visual Studio Express 2013.

I am using SFML 2.2 and Visual Studio Express 2013.

我只想加载纹理并将其应用到精灵,就像在 http://www.sfml-dev.org/tutorials/2.2/graphics-sprite.php.

I simply want to load a texture and apply it to a sprite just like it is done in the tutorials at http://www.sfml-dev.org/tutorials/2.2/graphics-sprite.php.

问题是 texture.loadFromFile() 对我来说根本不起作用.我试图将我的文件放在一千个不同的地方,但我总是得到相同的结果.最后我决定使用完整路径,同样的问题.我还尝试了不同的格式:PNG、GIF、JPG、BMP.我还尝试使用不同的软件保存它们:Photoshop、GIMP、paint.没有任何帮助.显示的唯一错误消息是:

The problem is that texture.loadFromFile() doesn't work at all for me. I have tried to place my file in a thousand different places and I always get the same result. Finally I decided to use the full path, same problem. I also tried different formats: PNG, GIF, JPG, BMP. I also tried to save them with different software: Photoshop, GIMP, paint. Nothing helps. The only error message displayed is:

无法加载图片

就是这样,最后只有一个双引号.

Exactly like that, only one double quote at the end.

帮助!

这是我尝试过的最少代码.

Here's the minimal code I tried.

#include <SFML/Graphics.hpp>

int main() {    
    sf::Texture texture;
    if (!texture.loadFromFile("C:\\temp.png"))
      return 1;

   return 0;
}

推荐答案

我知道问题出在哪里了.

I figured out what the problem was.

我在调试模式下运行,但在链接器中配置了附加依赖项下的非调试 .lib 文件.突然将配置切换到 Release 使一切正常.

I was running in debug mode but had configured the non-debug .lib files in the Linker under additional dependencies. Switching the configuration to Release suddenly made everything work.

为了使调试配置工作,我只需要将名称从 sfml-graphics.lib 更改为 sfml-graphics-d.lib(等等).成功了!

To get the debug configuration to work, I just had to change the names from sfml-graphics.lib to sfml-graphics-d.lib (and so on). That did the trick!

感谢大家的帮助!

这篇关于Texture.loadFromFile 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆