#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
// Here is a small helper for you ! Have a look.
#include "ResourcePath.hpp"
class Loader {
private:
sf::Texture& m_texture;
public:
bool loaded;
Loader(sf::Texture& texture) : m_texture(texture), loaded(false)
{ }
void load()
{
m_texture.loadFromFile(resourcePath() + "cute_image.jpg");
loaded = true;
}
};
int main(int, char const**)
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
window.clear();
window.display();
sf::Texture texture;
Loader loader(texture);
sf::Thread thread(&Loader::load, &loader);
thread.launch();
while (!loader.loaded)
sf::sleep(sf::milliseconds(10));
sf::Sprite sprite(texture);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) {
window.close();
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
window.close();
}
}
window.clear();
window.draw(sprite);
window.display();
}
return EXIT_SUCCESS;
}