-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
96 lines (72 loc) · 2.18 KB
/
main.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
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
#include "main.h"
void error_callback(int error, const char* description)
{
// Print error.
std::cerr << description << std::endl;
}
void setup_callbacks(GLFWwindow* window)
{
// Set the error callback.
glfwSetErrorCallback(error_callback);
// Set the window resize callback.
glfwSetWindowSizeCallback(window, Window::resizeCallback);
// Set the key callback.
glfwSetKeyCallback(window, Window::keyCallback);
}
void setup_opengl_settings()
{
// Enable depth buffering.
glEnable(GL_DEPTH_TEST);
// Related to shaders and z value comparisons for the depth buffer.
glDepthFunc(GL_LEQUAL);
// Set polygon drawing mode to fill front and back of each polygon.
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// Set clear color to black.
glClearColor(0.0, 0.0, 0.0, 0.0);
}
void print_versions()
{
// Get info of GPU and supported OpenGL version.
std::cout << "Renderer: " << glGetString(GL_RENDERER) << std::endl;
std::cout << "OpenGL version supported: " << glGetString(GL_VERSION)
<< std::endl;
//If the shading language symbol is defined.
#ifdef GL_SHADING_LANGUAGE_VERSION
std::cout << "Supported GLSL version is: " <<
glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
#endif
}
int main(void)
{
// Create the GLFW window.
GLFWwindow* window = Window::createWindow(640, 480);
if (!window)
exit(EXIT_FAILURE);
// Print OpenGL and GLSL versions.
print_versions();
// Setup callbacks.
setup_callbacks(window);
// Setup OpenGL settings.
setup_opengl_settings();
// Initialize the shader program; exit if initialization fails.
if (!Window::initializeProgram())
exit(EXIT_FAILURE);
// Initialize objects/pointers for rendering; exit if initialization fails.
if (!Window::initializeObjects())
exit(EXIT_FAILURE);
// Loop while GLFW window should stay open.
while (!glfwWindowShouldClose(window))
{
// Main render display callback. Rendering of objects is done here. (Draw)
Window::displayCallback(window);
// Idle callback. Updating objects, etc. can be done here. (Update)
Window::idleCallback();
}
// destroy objects created
Window::cleanUp();
// Destroy the window.
glfwDestroyWindow(window);
// Terminate GLFW.
glfwTerminate();
exit(EXIT_SUCCESS);
}