Creating a Window
Blank Window
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <cstdlib>
#include <optional>
int main() {
// Define the window size.
// A vector has multiple meanings in different fields, but in this case it is simply
// used to represent the width (x component) and height (y component) of the window.
static constexpr sf::Vector2u kWindowSize = {800U, 600U};
// Create a render window.
auto window = sf::RenderWindow(sf::VideoMode(kWindowSize), "Platformer");
// Set the frame rate limit (60FPS).
window.setFramerateLimit(60);
// Main loop.
while (window.isOpen()) {
// Event polling loop.
while (const std::optional event = window.pollEvent()) {
// Check for close event.
if (event->is<sf::Event::Closed>()) {
window.close();
}
}
// Clear the window.
window.clear();
// Drawing stuff will go here...
// Display the contents of the window.
window.display();
}
// Return success.
return EXIT_SUCCESS;
}Last updated