-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApplication.cpp
More file actions
127 lines (96 loc) · 2.24 KB
/
Application.cpp
File metadata and controls
127 lines (96 loc) · 2.24 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "Application.h"
#include <iostream>
using namespace std;
mat4 Application::projection = mat4::identity();
mat4 Application::view = mat4::identity();
static void error_callback(int error, const char* description)
{
cout << "Error: " << description << endl;
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
int Application::run()
{
GLFWwindow* window;
cout << "Hello OpenGL" << endl;
glfwSetErrorCallback(error_callback);
if (!glfwInit())
return EXIT_FAILURE;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(1024, 768, "OpenGL Lab", NULL, NULL);
if (!window)
{
glfwTerminate();
return EXIT_FAILURE;
}
glfwSetKeyCallback(window, key_callback);
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
{
cout << "Failed to initialize GLEW" << endl;
return EXIT_FAILURE;
}
glfwSwapInterval(1);
glPointSize(4);
glDisable(GL_CULL_FACE);
//glEnable(GL_CULL_FACE);
//glCullFace(GL_BACK);
//glFrontFace(GL_CCW);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.0, 1.0);
glClearColor(0.7, 0.7, 0.7, 1.0);
glClearDepth(1.0f);
setup();
while (!glfwWindowShouldClose(window))
{
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
update();
render();
glfwSwapBuffers(window);
glfwPollEvents();
GLuint error = glGetError();
if(error != GL_NO_ERROR)
{
cout << "OpenGL ERROR: " << error << endl;
}
}
teardown();
glfwDestroyWindow(window);
glfwTerminate();
return EXIT_SUCCESS;
}
int Application::getWidth()
{
return width;
}
int Application::getHeight()
{
return height;
}
void Application::setProjection(mat4 matrix)
{
projection = matrix;
}
mat4 Application::getProjection()
{
return projection;
}
void Application::setView(mat4 matrix)
{
view = matrix;
}
mat4 Application::getView()
{
return view;
}