-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopengl.cpp
265 lines (202 loc) · 6.73 KB
/
opengl.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//
// Created by Zohar Azar on 2019-01-12.
//
#include "my-opengl.h"
#include <GLKit/GLKMatrix4.h>
#include "my-leap.h"
/* Handler for window-repaint event. Call back when the window first appears and
whenever the window needs to be re-painted. */
// Using The STL Exception Library Increases The
// Chances That Someone Else Using Our Code Will Correctly
// Catch Any Exceptions That We Throw.
#include <stdexcept>
float verticesQuads[] = {
0.2f, 0.2f, 0.0f,
0.2f, 0.1f, 0.0f,
0.1f, 0.1f, 0.0f,
0.1f, 0.2f, 0.0f,
};
float verticesTriangles[] = {
-0.5f, -0.6f, 0.0f,
0.5f, -0.6f, 0.0f,
-0.2f, -0.2f, 0.0f,
0.5f, 0.6f, 0.0f,
-0.5f, 0.6f, 0.0f,
0.2f, 0.2f, 0.0f,
0.4f, 0.5f, 0.0f,
-0.4f, 0.5f, 0.0f,
0.1f, 0.1f, 0.0f,
};
float colorsQuads[] = {
1.0f, 0.0f, 0.0f, // red
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
};
float colorsFingers[] = {
1.0f, 0.0f, 0.0f, // red
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, // red
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, // red
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, // green
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, // green
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, // green
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f, // blue
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, // blue
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, // blue
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, // red
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, // red
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, // red
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, // green
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, // green
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, // green
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
float colorsTrangles[] = {
1.0f, 0.0f, 0.0f, // red
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, // green
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, // blue
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f,
};
void renderbitmap(float x, float y, void *font, char *string) {
char *c;
glRasterPos2f(x,y);
for (c=string; *c != '\0'; c++) {
glutBitmapCharacter(font,*c);
}
}
void introscreen() {
glColor3f(1.f,1.f,1.f);
char buf[100] = {0};
sprintf(buf,"%d %d",fingersBonesTriangles.size(), fingersBonesTrianglesColors.size());
renderbitmap(-0.8,0.8,GLUT_BITMAP_TIMES_ROMAN_24, buf);
}
void drawTriangle() {
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, verticesTriangles);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(3, GL_FLOAT, 0, colorsTrangles);
glDrawArrays(GL_TRIANGLES, 0, 9);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
void drawHands() {
glPointSize(10);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &fingersBonesTriangles[0]);
// glDisableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4, GL_FLOAT, 0, &fingersBonesTrianglesColors[0]);
// glDisableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINTS, 0, fingersBonesTriangles.size());
//glDisableClientState(GL_COLOR_ARRAY);
//glDisableClientState(GL_VERTEX_ARRAY);
introscreen();
}
void drawPoints() {
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, verticesQuads);
glEnableClientState(GL_COLOR_ARRAY);
glPointSize(10);
glColorPointer(3, GL_FLOAT, 0, colorsQuads);
glDrawArrays(GL_POINTS, 0, 4);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
void drawLines() {
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, verticesQuads);
glEnableClientState(GL_COLOR_ARRAY);
glLineWidth(10);
glColorPointer(3, GL_FLOAT, 0, colorsQuads);
glDrawArrays(GL_LINES, 0, 4);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
void drawQuad() {
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, verticesQuads);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(3, GL_FLOAT, 0, colorsQuads);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
void reshape(int w, int h) {
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLKMatrix4MakeOrtho(-1, 1, -1, -1, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
// activate and specify pointer to vertex array
if (isFingerBonesComputed && !isFingerBonesRendered) {
drawHands();
glutSwapBuffers();
isFingerBonesComputed = false;
isFingerBonesRendered = false;
}
}
Controller controller;
SampleListener listener;
void timer(int) {
glutPostRedisplay();
//vertices[0]+=0.01f;
glutTimerFunc(1000/30, timer, 0);
}
int main(int argc, char** argv) {
/* glGenVertexArraysAPPLE(1, &vao); //create VAO container and get ID for it
glBindVertexArrayAPPLE(vao); //bind to OpenGL context
glGenBuffers(1, &vbo);
//glBindBuffer(GL_ARRAY_BUFFER, vbo);//bind to context
//glBufferData(GL_ARRAY_BUFFER, sizeof(VertexFormat) * vertices.size(), &vertices[0], GL_STATIC_DRAW);*/
controller.addListener(listener); // init leap
controller.setPolicy(Leap::Controller::POLICY_BACKGROUND_FRAMES);
glutInit(&argc, argv); // Initialize GLUT
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(1024, 768); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
// glutReshapeFunc(reshape);
glutTimerFunc(0, timer,0);
glutMainLoop(); // Enter the infinitely event-processing loop
controller.removeListener(listener);
return 0;
}