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

Author Topic: SFML don't load image from file to texture  (Read 1684 times)

0 Members and 1 Guest are viewing this topic.

jackoi

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML don't load image from file to texture
« on: March 17, 2013, 03:42:37 pm »
Hello,
I have problem with loading image from file to texture, when I'm trying to load texture as in the tutorial I get error (Segmentation fault) and program is stopped, in console I have a lot strange objects, and SFML window are white. When I try system("dir") I see that the file "tlo.png" is in the right directory. I'm using Visual Studio 2012, and without Texture and Sprite classes, program compile correctly without errors. Thanks for help with that strange problem.
Here is my code:
#include <SFML/Graphics.hpp>

#include <iostream>

using namespace sf;

int main() {
        RenderWindow window( VideoMode( 800, 600, 32 ), "SFML");

        system("dir");

        Texture background;
       
        if (!background.loadFromFile("tlo.png")) // tlo.png 800x600
                return EXIT_FAILURE;

        Sprite sprite(background);
       

        CircleShape circle;
        circle.setFillColor(Color(255, 0, 0));
        circle.setRadius(50);
        circle.setOutlineThickness(1);
        circle.setOutlineColor(Color(255, 255, 255));
        circle.setPosition(-50, -50);

        RectangleShape rect;
        rect.setFillColor(Color(0, 0, 255));
        rect.setSize(Vector2f(64, 64));
        rect.setPosition(Vector2f(-32, -32));

        View view(Vector2f(0.0f, 0.0f), Vector2f(800, 600));
        window.setView(view);

        while(window.isOpen()) {
                Event event;

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

                        if(event.type == Event::KeyPressed && event.key.code == Keyboard::Right) {
                                circle.setPosition(circle.getPosition().x + 2, circle.getPosition().y);
                        }

                        if(event.type == Event::KeyPressed && event.key.code == Keyboard::Left) {
                                circle.setPosition(circle.getPosition().x - 2, circle.getPosition().y);
                        }

                        if(event.type == Event::KeyPressed && event.key.code == Keyboard::Up) {
                                circle.setPosition(circle.getPosition().x, circle.getPosition().y - 2);
                        }

                        if(event.type == Event::KeyPressed && event.key.code == Keyboard::Down) {
                                circle.setPosition(circle.getPosition().x, circle.getPosition().y + 2);
                        }
                }

                window.clear();
                window.draw(sprite);
                window.draw(circle);
                window.draw(rect);

                window.display();
        }

        return 0;
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML don't load image from file to texture
« Reply #1 on: March 17, 2013, 03:56:36 pm »
Where does the error occur? What does the debugger say?

Have you made sure that you link everything correctly (consistent configurations release/debug, static/dynamic)? Don't you use libraries that were compiled for VS 2010?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

jackoi

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML don't load image from file to texture
« Reply #2 on: March 17, 2013, 04:10:35 pm »
Error it's here:
if (!background.loadFromFile("tlo.png"))
everything is linked correctly, im using libraries and dll's form VS2010.
here its a error:


x = 0, y = 0, m_texure = 0
nothing loaded :(

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML don't load image from file to texture
« Reply #3 on: March 17, 2013, 04:51:20 pm »
im using libraries and dll's form VS2010
They are not compatible, recompile SFML or use exploiter's nightly builds.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: