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;
}