-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (95 loc) · 3.46 KB
/
main.cpp
File metadata and controls
107 lines (95 loc) · 3.46 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "check_gl.hpp"
#include <iostream>
#include "Game.hpp"
int main() {
// Initalize GLFW library
if (!glfwInit()) {
const char *errmsg;
glfwGetError(&errmsg);
if (!errmsg) errmsg = "(no error)";
std::cerr << "failed to initialize GLFW: " << errmsg << '\n';
return -1;
}
// Hint the version required: OpenGL 2.0
constexpr int version = 20;
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_NATIVE_CONTEXT_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, version / 10);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, version % 10);
if (version >= 33) {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
}
// enable 4x MSAA
glfwWindowHint(GLFW_SAMPLES, 4);
// Enable transparent framebuffer
constexpr bool transparent = false;
if (transparent) {
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_FALSE);
glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
}
// Create main window
constexpr char title[] = "Homework2: OpenCV 3D Logo";
GLFWwindow *window = glfwCreateWindow(1024, 768, title, NULL, NULL);
// Test if window creation succeed
if (!window) {
check_gl::opengl_show_glfw_error_diagnose();
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
// Switch to fullscreen mode
constexpr bool fullscreen = false;
if (fullscreen) {
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
if (monitor) {
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
if (mode) {
glfwSetWindowSize(window, mode->width, mode->height);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
std::cerr << "Entered fullscreen mode: " << mode->width << 'x' << mode->height
<< " at " << mode->refreshRate << " Hz\n";
}
}
} else {
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
if (monitor) {
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
if (mode) {
int width, height;
glfwGetWindowSize(window, &width, &height);
glfwSetWindowPos(window, (mode->width - width) / 2, (mode->height - height) / 2);
}
}
}
// Load glXXX function pointers (only after this you may use OpenGL functions)
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
glfwTerminate();
std::cerr << "GLAD failed to load GL functions\n";
return -1;
}
check_gl::opengl_try_enable_debug_message();
// Print diagnostic information
std::cerr << "OpenGL version: " << (const char *)glGetString(GL_VERSION) << '\n';
// Create game instance
auto &game = Game::get();
game.set_window(window);
// Initialize data structures
game.initialize();
// Start main game loop
while (!glfwWindowShouldClose(window)) {
// Render graphics
game.render();
// Update screen
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}