#include <SFML/Graphics.hpp>
sf::RenderWindow window(sf::VideoMode(1200,800,32), "Test");
sf::VertexArray createTriangle(sf::Color color, sf::Vector2f pos, float size) {
sf::VertexArray array(sf::Triangles, 3);
array[0].position = pos;
array[0].color = color;
array[1].position = sf::Vector2f(pos.x + size, pos.y);
array[1].color = sf::Color(0,0,0,0);
array[2].position = sf::Vector2f(pos.x + size, pos.y+size);
array[2].color = sf::Color(0,0,0,0);
return array;
}
int main(int argc, char *argv[]) {
// Create triangles
int count = 10;
sf::VertexArray vertices[count];
for (int i = 0; i < count; i++) {
// Use random color and random position
sf::Color randColor = sf::Color(rand()%255, rand()%255, rand()%255, rand()%255);
sf::Vector2f randPos(rand() % 600, rand() % 400);
vertices[i] = createTriangle(randColor, randPos, 800);
}
sf::Clock clock;
while (window.isOpen()) {
// Display FPS
float dt = clock.getElapsedTime().asMilliseconds();
displayFps(dt);
clock.restart();
window.clear();
// Draw triangles
for (int i = 0; i < count; i++) {
window.draw(vertices[i]);
}
window.display();
// Poll events
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
}
}