Yes, for first look It will be right, but issue is just masked behind endless loop (a lot of time was spend to avoid issue). Putting clear and display in main loop is good for dynamic image, not for static. Where calling display one time is enough. There is not place to play just with graphics. But this is not point of my post.
It looks unspecified number of draw iterations are skipped.
//...
window.create(mode, "", sf::Style::Fullscreen);
window.setFramerateLimit(60);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::KeyPressed:
window.close();
}
}
window.clear(sf::Color::Red); // Skipped X times before do allright
window.display();
}
//...
Perfectly It is seen in this code:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <cstdlib>
#include <ctime>
void wait(clock_t frequency, sf::RenderWindow *win);
int main() {
sf::VideoMode mode;
sf::RenderWindow window;
mode = sf::VideoMode::getDesktopMode();
if (!mode.isValid()) {
std::cout << "Window could not be created." << std::endl;
std::exit(1);
}
window.create(mode, "", sf::Style::Fullscreen);
window.setFramerateLimit(60);
window.clear(sf::Color::Red); // Fail
window.display();
wait(5000, &window);
window.clear(sf::Color::Green); // Ok
window.display();
wait(5000, &window);
window.clear(sf::Color::Blue); // Ok
window.display();
wait(5000, &window);
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::KeyPressed:
window.close();
}
}
window.clear(sf::Color::Black); // Ok
window.display();
}
return 0;
}
void wait(clock_t frequency, sf::RenderWindow *win) {
sf::Event event;
clock_t start = clock();
while ((clock() - start) < frequency) {
while (win->pollEvent(event));
}
}
It could be pass between Red, Green, Blue and Black color after five secs. But red part doesn't work. Default and Non style of window work well, Fullscreen style not.