Created
April 27, 2018 09:29
-
-
Save eXpl0it3r/a1235fd01bb239acd5b39e5771e42412 to your computer and use it in GitHub Desktop.
SFML "Benchmark"
This file contains hidden or 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 <random> | |
#include <vector> | |
#include <SFML/Graphics.hpp> | |
int main() | |
{ | |
sf::RenderWindow window{ {1280, 720}, "Test window" }; | |
std::random_device rd; | |
std::mt19937 gen(rd()); | |
std::normal_distribution<float> x_dist{ 0.f, 980.f }; | |
std::normal_distribution<float> y_dist{ 0.f, 220.f }; | |
std::normal_distribution<float> size_dist{ 50.f, 300.f }; | |
std::normal_distribution<float> r_dist{ 0, 255 }; | |
std::normal_distribution<float> g_dist{ 0, 255 }; | |
std::normal_distribution<float> b_dist{ 0, 255 }; | |
std::normal_distribution<float> a_dist{ 200, 255 }; | |
std::vector<sf::Vertex> vertices; | |
for(std::size_t i = 0; i < 100; i++) | |
{ | |
float x = x_dist(gen); | |
float y = y_dist(gen); | |
float size = size_dist(gen); | |
sf::Color color{ static_cast<sf::Uint8>(r_dist(gen)), static_cast<sf::Uint8>(g_dist(gen)), static_cast<sf::Uint8>(b_dist(gen)), static_cast<sf::Uint8>(a_dist(gen)) }; | |
vertices.emplace_back(sf::Vector2f{x, y}, color); | |
vertices.emplace_back(sf::Vector2f{x, y + size}, color); | |
vertices.emplace_back(sf::Vector2f{x + size, y + size }, color); | |
vertices.emplace_back(sf::Vector2f{x + size, y}, color); | |
} | |
sf::Clock clock; | |
while (window.isOpen()) | |
{ | |
sf::Event event; | |
while (window.pollEvent(event)) | |
{ | |
if (event.type == sf::Event::Closed) | |
{ | |
window.close(); | |
} | |
} | |
window.clear(); | |
window.draw(vertices.data(), vertices.size(), sf::Quads); | |
window.display(); | |
window.setTitle(std::to_string(1.f / clock.restart().asSeconds())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment