SFML community forums

Help => Graphics => Topic started by: timi19 on November 26, 2010, 11:26:04 am

Title: Can't load image in loadfromFile
Post by: timi19 on November 26, 2010, 11:26:04 am
Hello @ all,

i want to load an image in my render window, but it shows me only a white square with the size of my IntRect and the return is 5.

I use QT and the image is in the release directory.

i hope you can help me:)

Code: [Select]

#include <SFML/Graphics.hpp>

int main (){
    sf::RenderWindow window(
    sf::VideoMode (800, 600, 32), "Fenster", sf::Style::Close, sf::WindowSettings(32,0,0));
    window.UseVerticalSync(true);

    sf::Image image;
    if (!image.LoadFromFile("man.GIF")) {
        return 5;
    }

    sf::Sprite sprite;
    sprite.SetImage(image);
    sprite.SetPosition(sf::Vector2f(0, 0));
    sprite.SetSubRect(sf::IntRect(0, 0, 38 ,44));

    while (window.IsOpened()){
        sf::Event event;
        window.GetEvent(event);
        switch(event.Type){

        default:{
                break;
                }
        case sf::Event::Closed:{
                window.Close();
                break;
                }
        case sf::Event::KeyPressed:{
                switch (event.Key.Code){
                    default: break;
                    case sf::Key::Escape:
                        window.Close();
                        break;
                }
            }
        }

        window.Clear(sf::Color(200,200,200,255));
        window.Draw(sprite);
        window.Display();
    }
    return 0;
}

Title: Can't load image in loadfromFile
Post by: Groogy on November 26, 2010, 11:27:47 am
In the release directory? Your using Visual Studio right? Then you'll have to have the image n the project folder, unless you change the projects execution directory.
Title: Can't load image in loadfromFile
Post by: timi19 on November 26, 2010, 11:29:50 am
Quote from: "Groogy"
In the release directory? Your using Visual Studio right? Then you'll have to have the image n the project folder, unless you change the projects execution directory.


No I use QT, should i use SFML with Visual Studio?
Title: Can't load image in loadfromFile
Post by: Groogy on November 26, 2010, 11:35:20 am
Quote from: "timi19"
Quote from: "Groogy"
In the release directory? Your using Visual Studio right? Then you'll have to have the image n the project folder, unless you change the projects execution directory.


No I use QT, should i use SFML with Visual Studio?


Eeh what? no Qt? Do you mean the UI framework? That doesn't matter that's just a library and not an IDE. What IDE are you using?

*EDIT*
Anyway doesn't matter what IDE. Just check the projects execution directory setting and see where that is. It will execute the binary from that location. So just place your files in there.
Title: Can't load image in loadfromFile
Post by: Xorlium on November 26, 2010, 07:12:35 pm
I don't think it's the directory. If it was, the program would return 5, because sfml wouldn't have been able to load the image.

Have you tried with other types of images?
Title: Re: Can't load image in loadfromFile
Post by: Zamadatix on November 27, 2010, 04:16:58 am
Quote from: "Xorlium"
I don't think it's the directory. If it was, the program would return 5, because sfml wouldn't have been able to load the image.


Quote from: "timi19"
and the return is 5.
Title: Can't load image in loadfromFile
Post by: Groogy on November 27, 2010, 11:46:46 am
Code: [Select]
if (!image.LoadFromFile("man.GIF")) {
        return 5;
    }


THat's why it returns 5. Also by simply checking the documentation:
http://www.sfml-dev.org/documentation/2.0/classsf_1_1Image.htm#886032882e86461addacd198a9859f11

GIF images is not supported... Why do you even want to use a GIF image?