-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.cpp
More file actions
137 lines (100 loc) · 2.46 KB
/
display.cpp
File metadata and controls
137 lines (100 loc) · 2.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#ifndef DISPLAY
#define DISPLAY
#include "display.hpp"
#endif
#ifndef CON
#define CON
#include "convenience.hpp"
#endif
#ifndef OGLHPP
#define OGLHPP
#include "ogl.hpp"
#endif
#ifndef DOBJ
#define DOBJ
#include "D_Object.hpp"
#endif
#ifndef SHADE
#define SHADE
#include "Shader.hpp"
#endif
using namespace std;
using namespace glm;
#ifndef DISP
#define DISP
bool Display::context = false;
Display::Display(string title){
Setup();
v_matrix = mat4(1);
p_matrix = mat4(1);
window = glfwCreateWindow(640, 480, title.c_str(), NULL, NULL);
if(NULL == window){
fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU,"
" they are not 3.3 compatible.\n" );
glfwTerminate();
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if(glewInit() != GLEW_OK){
fprintf(stderr, "Failed to init GLEW\n");
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glClearColor(0, 0, 0.4f, 0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
}
Display::Display(string title, float width, float height){
Setup();
v_matrix = mat4(1);
p_matrix = mat4(1);
window = glfwCreateWindow(width, height, title.c_str(), NULL, NULL);
if(NULL == window){
fprintf(stderr, "Failed to open GLFW window. If you have an Intel GPU,"
" they are not 3.3 compatible.\n" );
glfwTerminate();
}
glfwMakeContextCurrent(window);
glewExperimental = true;
if(glewInit() != GLEW_OK){
fprintf(stderr, "Failed to init GLEW\n");
}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glClearColor(0, 0, 0.4f, 0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
}
void Display::Setup(){
if(context == false){
if(!glfwInit()){
fprintf( stderr, "Failed to initialize GLFW\n" );
}
// Set values for opengl
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
context = true;
}
}
GLFWwindow * Display::GetWindow(){
return window;
}
mat4 Display::GetView(){
return v_matrix;
}
mat4 Display::GetProjection(){
return p_matrix;
}
#endif