SFML映像未加载 [英] SFML image not loading

查看:320
本文介绍了SFML映像未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Xcode与SFML。我把我的文件放在Xcode项目中,将其复制到目录。但是,我仍然无法将其加载到程序中。任何想法?

I am using Xcode with SFML. I placed my file in the Xcode project which copied it to the directory. However, I still am unable to load it into the program. Any ideas?

代码:

int main(int argc, const char * argv[])
{
    sf::RenderWindow(window);
    window.create(sf::VideoMode(800, 600), "My window");

    sf::Texture img;
    if(!img.loadFromFile("colorfull small.jpg")) return 0;

    sf::Sprite sprite;
    sprite.setTexture(img);

    window.draw(sprite);
    window.display();

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed) window.close();
        }
    }
    return 0;
}

编译器:

compiler:

目录:

谢谢

推荐答案

错误有几个原因:

sfml文档


某些格式不支持选项,例如渐进式jpeg。

Some format options are not supported, like progressive jpeg.

找不到文件,因为文件名中有空格(重命名文件,例如colorfull_small.jpg)

It doesn't find the file because the filename has spaces in it (rename the file, e.g colorfull_small.jpg)

程序的工作目录没有.jpg文件(您可以使用 getcwd(NULL)(可在 #include< unistd.h> ))

The program's working directory does not have the .jpg file (you can print it using getcwd(NULL) (available in #include <unistd.h>))

这篇关于SFML映像未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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