Created
October 31, 2015 01:24
-
-
Save eXpl0it3r/6a0d9c911540ec9ac142 to your computer and use it in GitHub Desktop.
Non-blocking screenshots with SFML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SFML/Graphics.hpp> | |
#include <thread> | |
int main() | |
{ | |
sf::RenderWindow window({1920, 1080}, "Screenshot!"); | |
sf::Texture tex; | |
tex.create(1920, 1080); | |
sf::Clock cl; | |
while(window.isOpen()) | |
{ | |
sf::Time dt = cl.restart(); | |
window.setTitle(std::to_string(1.f/dt.asSeconds())); | |
sf::Event event; | |
while(window.pollEvent(event)) | |
{ | |
if(event.type == sf::Event::Closed) | |
window.close(); | |
else if(event.type == sf::Event::KeyPressed) | |
{ | |
tex.update(window); | |
sf::Image img = tex.copyToImage(); | |
std::thread t([img]() { | |
img.saveToFile("test.png"); | |
}); | |
t.detach(); | |
} | |
} | |
window.clear(sf::Color(0xFF0000FF)); | |
window.display(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment