-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopengl_init.cpp
132 lines (109 loc) · 2.61 KB
/
opengl_init.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
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
#if defined(WIN32)
#define _USE_MATH_DEFINES // Make MS math.h define M_PI
#endif
#include "tests.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <random>
#include <GLFW/glfw3.h>
#if defined(WIN32)
#pragma comment(lib, "glfw3dll.lib")
#else
#endif
#include "Timer.h"
#include "linmath.h"
#include "mesh_utils.h"
#include "input.h"
#include "Camera.h"
#include "HydraXMLHelpers.h"
#include <algorithm>
///////////////////////////////////////////////////////////////////////////////////
using namespace HydraXMLHelpers;
extern Input g_input;
static GLFWwindow* g_window = nullptr;
static int g_width = 1024;
static int g_height = 1024;
static int g_filling = 0;
static void key(GLFWwindow* window, int k, int s, int action, int mods)
{
if (action != GLFW_PRESS) return;
switch (k)
{
case GLFW_KEY_Z:
//if (mods & GLFW_MOD_SHIFT)
// view_rotz -= 5.0;
//else
// view_rotz += 5.0;
break;
case GLFW_KEY_ESCAPE:
glfwSetWindowShouldClose(window, GL_TRUE);
break;
case GLFW_KEY_UP:
//view_rotx += 5.0;
break;
case GLFW_KEY_DOWN:
//view_rotx -= 5.0;
break;
case GLFW_KEY_LEFT:
//view_roty += 5.0;
break;
case GLFW_KEY_RIGHT:
//view_roty -= 5.0;
break;
case GLFW_KEY_SPACE:
if (g_filling == 0)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
g_filling = 1;
}
else
{
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
g_filling = 0;
}
break;
default:
return;
}
}
void initGLIfNeeded(int a_width, int a_height, const char* a_name)
{
static bool firstCall = true;
if (firstCall)
{
g_width = a_width;
g_height = a_height;
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_DEPTH_BITS, 24);
g_window = glfwCreateWindow(g_width, g_height, a_name, NULL, NULL);
if (!g_window)
{
fprintf(stderr, "Failed to open GLFW window\n");
glfwTerminate();
exit(EXIT_FAILURE);
}
// Set callback functions
//glfwSetFramebufferSizeCallback(g_window, reshape);
glfwSetKeyCallback(g_window, key);
glfwMakeContextCurrent(g_window);
//gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
glfwSwapInterval(1);
glfwGetFramebufferSize(g_window, &g_width, &g_height);
//reshape(g_window, g_width, g_height);
firstCall = false;
}
else
{
g_width = a_width;
g_height = a_height;
glfwSetWindowSize(g_window, g_width, g_height);
glfwSetWindowTitle(g_window, a_name);
}
}