I'm getting some curious screen flickering. Below is the code. I'm just drawing a triangle at a random point on the screen every second. The idea is to keep what has been drawn previously and just draw another triangle. I'm don't clear the screen between redraws and reuse the shape object. I assume this is a valid approach.
Here's an album with the first few frames the code generates. Pictures are in order of appearance. It's curious that every odd frame has the first triangle in it. But every even frame don't have the first triangle. Why doesn't all frames have the first triangle in it?
http://imgur.com/a/nd5xW#include "stdafx.h"
#include <Windows.h>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(1024, 576), "SFML works!");
sf::Vector2u windowSize = window.getSize();
sf::CircleShape triangle(50, 3);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed ||
event.type == event.KeyPressed && event.key.code == sf::Keyboard::Escape)
{
window.close();
}
}
int posX = rand() % windowSize.x;
int posY = rand() % windowSize.y;
triangle.setPosition(posX,posY);
int r = rand() % 255;
int g = rand() % 255;
int b = rand() % 255;
triangle.setFillColor(sf::Color::Color(r, g, b));
window.draw(triangle);
window.display();
Sleep(1000);
}
return 0;
}