Reputation: 707
I'm used to using SDL for C++ but I heard that SFML is better so I tried it. I tried to render a basic sprite and that didn't work. Then I tried to clear the window to a different colour and that didn't work. It's simple code so what is going on? (Spacing is a little off for some reason, sorry)
#include <iostream>
#include "SFML/Graphics.hpp"
int main(){
sf::RenderWindow window(sf::VideoMode(640, 480), "It worked");
sf::Texture boxTexture;
boxTexture.loadFromFile("box.png");
while (window.isOpen()){
window.clear(sf::Color::Blue);
sf::CircleShape circle;
circle.setRadius(10);
circle.setPosition(1, 1);
circle.setFillColor(sf::Color::Blue);
window.draw(circle);
window.display();
}
return 0;
}
All this does is display a white screen... It won't change the background to blue. Does anyone know what I am doing wrong?
Upvotes: 0
Views: 1192
Reputation: 1993
Even if you don't need it, you have to put the event handling loop. From the SFML tutorial page:
A mistake that people often make is to forget the event loop, simply because they don't yet care about handling events (they use real-time inputs instead). Without an event loop, the window will become unresponsive. It is important to note that the event loop has two roles: in addition to providing events to the user, it gives the window a chance to process its internal events too, which is required so that it can react to move or resize user actions.
You can learn more about here
Hope this helps
Upvotes: 2