-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleWindowGLFW.cpp
57 lines (47 loc) · 1.39 KB
/
simpleWindowGLFW.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// STL
#include <cstdlib>
#include <optional>
#include <iostream>
// GLFW
#include <GLFW/glfw3.h>
static auto parseProgramOptions(int argc, char** argv)
-> std::optional<std::pair<int, int>> {
if(argc != 3) {
std::cerr << "Usage:\n\t" << argv[0] << " width height\n";
return std::nullopt;
}
return std::make_pair(
std::stoi(argv[1]),
std::stoi(argv[2])
);
}
int main(int argc, char* argv[]) {
if(!glfwInit()) {
return EXIT_FAILURE;
}
int width = 640;
int height = 480;
if(const auto args = parseProgramOptions(argc, argv);
args) {
int x, y, w, h;
auto pPrimaryMonitor = glfwGetPrimaryMonitor();
glfwGetMonitorWorkarea(pPrimaryMonitor, &x, &y, &w, &h);
width = std::min(args.value().first, w-x);
height = std::min(args.value().second, h-y);
}
constexpr std::string_view sWindowTitle = "HelloWorld!";
auto pWindow = glfwCreateWindow(width, height, sWindowTitle.data(), nullptr, nullptr);
if(!pWindow) {
glfwTerminate();
return EXIT_FAILURE;
}
while(!glfwWindowShouldClose(pWindow)) {
glfwSwapBuffers(pWindow);
glfwPollEvents();
}
glfwDestroyWindow(pWindow);
glfwTerminate();
exit(EXIT_SUCCESS);
}