Skip to content

Instantly share code, notes, and snippets.

@eXpl0it3r
Last active September 25, 2017 14:24
Show Gist options
  • Save eXpl0it3r/0862584105d729526839e77686f064ab to your computer and use it in GitHub Desktop.
Save eXpl0it3r/0862584105d729526839e77686f064ab to your computer and use it in GitHub Desktop.
SFML Test - Loading Images (JPG)
#include <string>
#include <vector>
#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#include <SFML/Graphics.hpp>
int main()
{
std::string path = "jpg/google";
std::vector<std::string> files;
std::vector<std::string> good;
std::vector<std::string> bad;
for (auto & p : fs::directory_iterator(path))
files.emplace_back(p.path().string());
sf::RenderWindow window{sf::VideoMode{1024, 756}, "Test"};
window.setFramerateLimit(30);
sf::Texture texture;
sf::Sprite sprite(texture);
while(window.isOpen())
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
window.close();
}
if(!files.empty())
{
std::string& file = files.back();
std::cout << "Testing: " << file << "\n";
if(texture.loadFromFile(file))
good.push_back(file);
else
bad.push_back(file);
files.pop_back();
sprite.setTexture(texture, true);
}
window.clear();
window.draw(sprite);
window.display();
}
std::cout << "The Goods\n";
for(auto& g : good)
std::cout << g << "\n";
std::cout << "The Bads\n";
for(auto& b : bad)
std::cout << b << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment