-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleWindowSFML.cpp
41 lines (35 loc) · 969 Bytes
/
simpleWindowSFML.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// STL
#include <iostream>
#include <optional>
// SFML
#include <SFML/Window.hpp>
static auto parseProgramOptions(int argc, char** argv)
-> std::optional<std::pair<uint32_t, uint32_t>> {
if(argc != 3) {
return std::nullopt;
}
return std::make_pair(
std::stoi(argv[1]),
std::stoi(argv[2])
);
}
auto main(int argc, char* argv[]) -> int{
auto width = 640U;
auto height = 480U;
if(const auto args = parseProgramOptions(argc, argv);
args) {
width = std::min(args.value().first, sf::VideoMode::getDesktopMode().width);
height = std::min(args.value().second, sf::VideoMode::getDesktopMode().height);
}
sf::Window window(sf::VideoMode(width, height), "My window");
while(window.isOpen()) {
sf::Event event;
while(window.pollEvent(event)) {
if(event.type == sf::Event::Closed) {
window.close();
}
}
window.display();
}
return EXIT_SUCCESS;
}