-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (39 loc) · 1.44 KB
/
main.cpp
File metadata and controls
49 lines (39 loc) · 1.44 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
//Includes all opengl headers too.
#include <GLFW/glfw3.h>
//Includes all cout functions, i.e. std::cout.
#include <iostream>
//Glfw error function, all errors will be notified by this function.
void error_callback(int error, const char* description) {
std::cout << "Error code: " << error << " - " << description << std::endl;
}
int main(int argc, char** argv) {
//Installs a callback function for glfw errors, if any error occurs the function will be called.
glfwSetErrorCallback(error_callback);
//Initializes the glfw framework, this function must be called.
if (!glfwInit()) {
std::cout << "Error glfwInit" << std::endl;
return 1;
}
//Creates a window with the opengl context
GLFWwindow* window = glfwCreateWindow(800, 600, "Hello World!", NULL, NULL);
if (!window) {
std::cout << "Error glfwCreateWindow" << std::endl;
glfwTerminate();
return 1;
}
//Sets this window as the current render context, after call this function the opengl functions will be enabled.
glfwMakeContextCurrent(window);
//Main loop, checks if the window still alive
while (!glfwWindowShouldClose(window)) {
//Process all the events, inputs, window resize, etc.
glfwPollEvents();
//Sends the back buffer to render.
glfwSwapBuffers(window);
}
//Frees resources associates with the window.
glfwDestroyWindow(window);
//Frees all resources used by glfw framework.
glfwTerminate();
//Everything ended ok.
return 0;
}