-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglut_1000.cpp
More file actions
367 lines (301 loc) · 10.6 KB
/
glut_1000.cpp
File metadata and controls
367 lines (301 loc) · 10.6 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#include "stdafx.h"
#include "glut_1000.h"
#include "GL/glew.h"
#if defined (ACE_WIN32) || defined (ACE_WIN64)
#include "gl/GL.h"
#else
#include "GL/gl.h"
#endif // ACE_WIN32 || ACE_WIN64
#include "GL/freeglut.h"
#include "glm/gtc/matrix_transform.hpp"
#include "ace/Assert.h"
#include "ace/Log_Msg.h"
#include "common_tools.h"
#include "common_file_tools.h"
#include "common_gl_defines.h"
#include "common_gl_tools.h"
#include "defines_48.h"
#include "engine_common.h"
void
engine_glut_1000_reshape (int width_in,
int height_in)
{
glViewport (0, 0, width_in, height_in);
//glMatrixMode (GL_PROJECTION);
//glLoadIdentity ();
//ACE_ASSERT (height_in);
//gluPerspective (45.0,
// width_in / static_cast<GLdouble> (height_in),
// 0.1, -1000.0);
//glOrtho (static_cast<GLdouble> (-width_in / 2.0), static_cast<GLdouble> (width_in / 2.0),
// static_cast<GLdouble> (height_in / 2.0), static_cast<GLdouble> (-height_in / 2.0), 150.0, -150.0);
//glMatrixMode (GL_MODELVIEW);
}
void
engine_glut_1000_key (unsigned char key_in,
int x,
int y)
{
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
switch (key_in)
{
case 27: /* Escape */
glutLeaveMainLoop ();
break;
case 32: /* Space */
cb_data_p->isSpaceKeyPressed = true;
break;
case 'd':
cb_data_p->isDKeyPressed = true;
break;
case 'r':
cb_data_p->isRKeyPressed = true;
break;
case 't':
cb_data_p->isTKeyPressed = true;
break;
default:
break;
} // end SWITCH
}
void
engine_glut_1000_key_up (unsigned char key_in,
int x,
int y)
{
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
switch (key_in)
{
case 32: /* Space */
cb_data_p->isSpaceKeyPressed = false;
break;
case 'd':
cb_data_p->isDKeyPressed = false;
break;
case 'r':
cb_data_p->isRKeyPressed = false;
break;
case 't':
cb_data_p->isTKeyPressed = false;
break;
default:
break;
} // end SWITCH
}
void
engine_glut_1000_key_special (int key_in,
int x,
int y)
{
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
switch (key_in)
{
//case 114: // LCtrl
//case 115: // RCtrl
// cb_data_p->isCtrlPressed = true;
// break;
default:
break;
} // end SWITCH
}
void
engine_glut_1000_key_special_up (int key_in,
int x,
int y)
{
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
switch (key_in)
{
//case 114: // LCtrl
//case 115: // RCtrl
// cb_data_p->isCtrlPressed = false;
// break;
default:
break;
} // end SWITCH
}
void
engine_glut_1000_menu (int entry_in)
{
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
switch (entry_in)
{
case 0:
cb_data_p->wireframe = !cb_data_p->wireframe;
break;
default:
break;
} // end SWITCH
}
void
engine_glut_1000_mouse_button (int button, int state, int x, int y)
{
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
switch (button)
{
case GLUT_LEFT_BUTTON:
{
cb_data_p->mouseLMBPressed = (state == GLUT_DOWN);
break;
}
default:
break;
} // end IF
}
void
engine_glut_1000_mouse_move (int x, int y)
{
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
cb_data_p->mouseX = x;
cb_data_p->mouseY = y;
}
void
engine_glut_1000_timer (int v)
{
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
glutPostRedisplay ();
glutTimerFunc (1000 / 60,
engine_glut_1000_timer,
v);
}
void
engine_glut_1000_draw (void)
{
static int frame_counter_i = 1;
struct Engine_OpenGL_GLUT_1000_CBData* cb_data_p =
static_cast<struct Engine_OpenGL_GLUT_1000_CBData*> (glutGetWindowData ());
ACE_ASSERT (cb_data_p);
//if (cb_data_p->isSpaceKeyPressed)
// frame_counter_i = 1;
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// reset transformations
//glMatrixMode (GL_MODELVIEW);
//glLoadIdentity ();
glPolygonMode (GL_FRONT_AND_BACK,
cb_data_p->wireframe ? GL_LINE : GL_FILL);
// compute elapsed time
#if defined (ACE_WIN32) || defined (ACE_WIN64)
std::chrono::steady_clock::time_point tp2 = std::chrono::high_resolution_clock::now ();
#elif defined (ACE_LINUX)
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp2 = std::chrono::high_resolution_clock::now ();
#else
#error missing implementation, aborting
#endif // ACE_WIN32 || ACE_WIN64 || ACE_LINUX
std::chrono::duration<float> elapsed_time = tp2 - cb_data_p->tp1;
std::chrono::milliseconds d =
std::chrono::duration_cast<std::chrono::milliseconds> (elapsed_time);
glBindVertexArray (cb_data_p->VAO);
// render pass 1
cb_data_p->shader1.use ();
// update uniforms
glProgramUniform2f (cb_data_p->shader1.id_, cb_data_p->S1resolutionLoc,
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_WIDTH),
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_HEIGHT));
glProgramUniform1i (cb_data_p->shader1.id_, cb_data_p->S1channel3Loc,
static_cast<GLint> (4));
// draw render pass 1 to framebuffer object (--> textureS1)
glBindFramebuffer (GL_FRAMEBUFFER, cb_data_p->FBO1);
glDrawArrays (GL_TRIANGLES, 0, 6); // 2 triangles --> 6 vertices
//glDrawArrays (GL_QUADS, 0, 4); // 1 quad --> 4 vertices
glBindFramebuffer (GL_FRAMEBUFFER, 0);
// render pass 2
cb_data_p->shader2.use ();
// update uniforms
glProgramUniform2f (cb_data_p->shader2.id_, cb_data_p->S2resolutionLoc,
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_WIDTH),
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_HEIGHT));
glProgramUniform1i (cb_data_p->shader2.id_, cb_data_p->S2channel0Loc,
static_cast<GLint> (1));
glProgramUniform1i (cb_data_p->shader2.id_, cb_data_p->S2channel3Loc,
static_cast<GLint> (4));
// draw render pass 2 to framebuffer object (--> textureS2)
glBindFramebuffer (GL_FRAMEBUFFER, cb_data_p->FBO2);
glDrawArrays (GL_TRIANGLES, 0, 6); // 2 triangles --> 6 vertices
//glDrawArrays (GL_QUADS, 0, 4); // 1 quad --> 4 vertices
glBindFramebuffer (GL_FRAMEBUFFER, 0);
// render pass 3
cb_data_p->shader3.use ();
// update uniforms
glProgramUniform2f (cb_data_p->shader3.id_, cb_data_p->S3resolutionLoc,
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_WIDTH),
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_HEIGHT));
glProgramUniform1i (cb_data_p->shader3.id_, cb_data_p->S3channel1Loc,
static_cast<GLint> (2));
// draw render pass 3 to framebuffer object (--> textureS3)
glBindFramebuffer (GL_FRAMEBUFFER, cb_data_p->FBO3);
glDrawArrays (GL_TRIANGLES, 0, 6); // 2 triangles --> 6 vertices
//glDrawArrays (GL_QUADS, 0, 4); // 1 quad --> 4 vertices
glBindFramebuffer (GL_FRAMEBUFFER, 0);
// render pass 4
cb_data_p->shader4.use ();
// update uniforms
glProgramUniform2f (cb_data_p->shader4.id_, cb_data_p->S4resolutionLoc,
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_WIDTH),
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_HEIGHT));
glProgramUniform1f (cb_data_p->shader4.id_, cb_data_p->S4timeLoc,
static_cast<GLfloat> (d.count () * 0.001f));
glProgramUniform1i (cb_data_p->shader4.id_, cb_data_p->S4frameLoc,
static_cast<GLint> (frame_counter_i - 1));
glProgramUniform4f (cb_data_p->shader4.id_, cb_data_p->S4mouseLoc,
static_cast<GLfloat> (cb_data_p->mouseX),
static_cast<GLfloat> (Common_GL_Tools::map (cb_data_p->mouseY, 0, ENGINE_GLUT_1000_DEFAULT_HEIGHT - 1, ENGINE_GLUT_1000_DEFAULT_HEIGHT - 1, 0)),
static_cast<GLfloat> (cb_data_p->mouseLMBPressed ? 1 : 0),
0.0f);
glProgramUniform4i (cb_data_p->shader4.id_, cb_data_p->S4keysLoc,
static_cast<GLint> (cb_data_p->isSpaceKeyPressed ? 1 : 0),
static_cast<GLint> (cb_data_p->isDKeyPressed ? 1 : 0),
static_cast<GLint> (cb_data_p->isRKeyPressed ? 1 : 0),
static_cast<GLint> (cb_data_p->isTKeyPressed ? 1 : 0));
glProgramUniform1i (cb_data_p->shader4.id_, cb_data_p->S4channel2Loc,
static_cast<GLint> (3));
glProgramUniform1i (cb_data_p->shader4.id_, cb_data_p->S4channel3Loc,
static_cast<GLint> (4));
// draw render pass 4 to framebuffer object (--> textureS4)
glBindFramebuffer (GL_FRAMEBUFFER, cb_data_p->FBO4);
glDrawArrays (GL_TRIANGLES, 0, 6); // 2 triangles --> 6 vertices
//glDrawArrays (GL_QUADS, 0, 4); // 1 quad --> 4 vertices
glBindFramebuffer (GL_FRAMEBUFFER, 0);
// render pass 5
cb_data_p->shader5.use ();
// update uniforms
glProgramUniform2f (cb_data_p->shader5.id_, cb_data_p->S5resolutionLoc,
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_WIDTH),
static_cast<GLfloat> (ENGINE_GLUT_1000_DEFAULT_HEIGHT));
glProgramUniform1i (cb_data_p->shader5.id_, cb_data_p->S5channel3Loc,
static_cast<GLint> (4));
// draw render pass 5 to screen
glDrawArrays (GL_TRIANGLES, 0, 6); // 2 triangles --> 6 vertices
//glDrawArrays (GL_QUADS, 0, 4); // 1 quad --> 4 vertices
glBindVertexArray (0);
glutSwapBuffers ();
++frame_counter_i;
}
void
engine_glut_1000_idle (void)
{
//glutPostRedisplay ();
}
void
engine_glut_1000_visible (int vis)
{
if (vis == GLUT_VISIBLE)
glutIdleFunc (engine_glut_1000_idle);
else
glutIdleFunc (NULL);
}