Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Can't load image in loadfromFile  (Read 4412 times)

0 Members and 1 Guest are viewing this topic.

timi19

  • Newbie
  • *
  • Posts: 2
    • View Profile
Can't load image in loadfromFile
« 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;
}


Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Can't load image in loadfromFile
« Reply #1 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.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

timi19

  • Newbie
  • *
  • Posts: 2
    • View Profile
Can't load image in loadfromFile
« Reply #2 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?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Can't load image in loadfromFile
« Reply #3 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.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
Can't load image in loadfromFile
« Reply #4 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?

Zamadatix

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Can't load image in loadfromFile
« Reply #5 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.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Can't load image in loadfromFile
« Reply #6 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?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

 

anything