|
@@ -1,604 +0,0 @@
|
1
|
|
-/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
|
2
|
|
-#ifdef SDL_UNIT_TEST
|
3
|
|
-#include <stdio.h>
|
4
|
|
-#include <string.h>
|
5
|
|
-#include <stdlib.h>
|
6
|
|
-
|
7
|
|
-#ifdef USING_OPENGL
|
8
|
|
-
|
9
|
|
-#ifdef __APPLE__
|
10
|
|
-#include <OpenGL/gl.h>
|
11
|
|
-#include <OpenGL/glu.h>
|
12
|
|
-#else
|
13
|
|
-#include <GL/gl.h>
|
14
|
|
-#include <GL/glu.h>
|
15
|
|
-#endif
|
16
|
|
-# include <SDL/SDL.h>
|
17
|
|
-# include <Texture.h>
|
18
|
|
-
|
19
|
|
-// Implement these functions in your Unit Test
|
20
|
|
-void renderScene(float time, float lastTime);
|
21
|
|
-void handleKey(int key);
|
22
|
|
-void handleArgKey(char key);
|
23
|
|
-void initScene(int argc, char *argv[]);
|
24
|
|
-
|
25
|
|
-// Call this function to start SDL Unit Test
|
26
|
|
-int runSDLUnitTest(int argc, char *argv[]);
|
27
|
|
-
|
28
|
|
-//////////////////////////////////////////////////////////////////
|
29
|
|
-Texture gTexture;
|
30
|
|
-
|
31
|
|
-char gTitle[128];
|
32
|
|
-float gYaw = 0.0f;
|
33
|
|
-bool gYawOn = true;
|
34
|
|
-float gPitch = -20.0f;
|
35
|
|
-float gScale = 1.0f;
|
36
|
|
-float gLightPos[] = { 0.0, 512.0, 1024.0, 0.0 };
|
37
|
|
-unsigned int gWidth = 640, gHeight = 460;
|
38
|
|
-
|
39
|
|
-
|
40
|
|
-void event_resize(unsigned int width, unsigned int height);
|
41
|
|
-
|
42
|
|
-void handle_key(int key)
|
43
|
|
-{
|
44
|
|
- static bool wireframe = false;
|
45
|
|
- static bool alphaBlend = false;
|
46
|
|
- static bool lighting = false;
|
47
|
|
-
|
48
|
|
- switch (key)
|
49
|
|
- {
|
50
|
|
- case SDLK_F5:
|
51
|
|
- wireframe = !wireframe;
|
52
|
|
-
|
53
|
|
- if (wireframe)
|
54
|
|
- {
|
55
|
|
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
56
|
|
- }
|
57
|
|
- else
|
58
|
|
- {
|
59
|
|
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
60
|
|
- }
|
61
|
|
-
|
62
|
|
- printf("%sabled wireframe rendering\n", wireframe ? "En" : "Dis");
|
63
|
|
- break;
|
64
|
|
- case SDLK_F6:
|
65
|
|
- alphaBlend = !alphaBlend;
|
66
|
|
-
|
67
|
|
- if (alphaBlend)
|
68
|
|
- {
|
69
|
|
- glEnable(GL_BLEND);
|
70
|
|
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
71
|
|
- glAlphaFunc(GL_GREATER, 0);
|
72
|
|
- }
|
73
|
|
- else
|
74
|
|
- {
|
75
|
|
- glDisable(GL_BLEND);
|
76
|
|
- }
|
77
|
|
-
|
78
|
|
- printf("%sabled alpha blending\n", alphaBlend ? "En" : "Dis");
|
79
|
|
- break;
|
80
|
|
- case SDLK_F7:
|
81
|
|
- lighting = !lighting;
|
82
|
|
-
|
83
|
|
- if (lighting)
|
84
|
|
- {
|
85
|
|
- static bool firsttime = true;
|
86
|
|
-
|
87
|
|
-
|
88
|
|
- glEnable(GL_LIGHTING);
|
89
|
|
-
|
90
|
|
- if (firsttime)
|
91
|
|
- {
|
92
|
|
- float specular[] = { 0.6, 0.6, 0.6, 1.0 };
|
93
|
|
- float ambient[] = { 0.64, 0.64, 0.64, 1.0 };
|
94
|
|
- float shine[] = { 50.0 };
|
95
|
|
-
|
96
|
|
-
|
97
|
|
- // Caustic fx possible with mod amb?
|
98
|
|
- glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
|
99
|
|
- glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
|
100
|
|
- //glMaterialfv(GL_FRONT, GL_DIFFUSE, ambient);
|
101
|
|
- glMaterialfv(GL_FRONT, GL_SHININESS, shine);
|
102
|
|
- glLightfv(GL_LIGHT0, GL_POSITION, gLightPos);
|
103
|
|
- glEnable(GL_LIGHT0);
|
104
|
|
-
|
105
|
|
- glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
|
106
|
|
-
|
107
|
|
- //glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 0);
|
108
|
|
- //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, WHITE);
|
109
|
|
- //glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, WHITE);
|
110
|
|
- //glLightModelfv(GL_LIGHT_MODEL_AMBIENT, DIM_WHITE);
|
111
|
|
- //glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, cutoff);
|
112
|
|
- //glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
113
|
|
- //glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
|
114
|
|
- //glLightfv(GL_LIGHT0, GL_DIFFUSE, color);
|
115
|
|
-
|
116
|
|
- firsttime = false;
|
117
|
|
- }
|
118
|
|
- }
|
119
|
|
- else
|
120
|
|
- {
|
121
|
|
- glDisable(GL_LIGHTING);
|
122
|
|
- }
|
123
|
|
- break;
|
124
|
|
- case SDLK_F8:
|
125
|
|
- gYawOn = !gYawOn;
|
126
|
|
- break;
|
127
|
|
- case SDLK_F9:
|
128
|
|
- gTexture.glScreenShot("screenshot", gWidth, gHeight);
|
129
|
|
- break;
|
130
|
|
- case SDLK_F10:
|
131
|
|
- event_resize(640, 460);
|
132
|
|
- break;
|
133
|
|
- case SDLK_F11:
|
134
|
|
- event_resize(800, 600);
|
135
|
|
- break;
|
136
|
|
- case SDLK_F12:
|
137
|
|
- event_resize(1024, 768);
|
138
|
|
- break;
|
139
|
|
- case SDLK_RIGHT:
|
140
|
|
- ++gYaw;
|
141
|
|
- break;
|
142
|
|
- case SDLK_LEFT:
|
143
|
|
- --gYaw;
|
144
|
|
- break;
|
145
|
|
- case SDLK_UP:
|
146
|
|
- ++gPitch;
|
147
|
|
- break;
|
148
|
|
- case SDLK_DOWN:
|
149
|
|
- --gPitch;
|
150
|
|
- break;
|
151
|
|
- case '-':
|
152
|
|
- if (gScale *= 0.75f > 0.000001)
|
153
|
|
- gScale *= 0.75f;
|
154
|
|
- break;
|
155
|
|
- case '=':
|
156
|
|
- gScale *= 1.25f;
|
157
|
|
- break;
|
158
|
|
- case 'i':
|
159
|
|
- gLightPos[1] += 16.0f;
|
160
|
|
- glLightfv(GL_LIGHT0, GL_POSITION, gLightPos);
|
161
|
|
- break;
|
162
|
|
- case 'k':
|
163
|
|
- gLightPos[1] -= 16.0f;
|
164
|
|
- glLightfv(GL_LIGHT0, GL_POSITION, gLightPos);
|
165
|
|
- break;
|
166
|
|
- case 'j':
|
167
|
|
- gLightPos[2] -= 16.0f;
|
168
|
|
- glLightfv(GL_LIGHT0, GL_POSITION, gLightPos);
|
169
|
|
- break;
|
170
|
|
- case 'l':
|
171
|
|
- gLightPos[2] += 16.0f;
|
172
|
|
- glLightfv(GL_LIGHT0, GL_POSITION, gLightPos);
|
173
|
|
- break;
|
174
|
|
- case 'h':
|
175
|
|
- printf("[SDLUnitTest.test]\n");
|
176
|
|
- printf("----------------------------------\n");
|
177
|
|
- printf("ESC - Exit\n");
|
178
|
|
- printf("F5 - Toggle wireframe rendering\n");
|
179
|
|
- printf("F6 - Toggle alpha blending\n");
|
180
|
|
- printf("F8 - Toggle scene rotation\n");
|
181
|
|
- printf("F7 - Toggle lighting\n");
|
182
|
|
- printf("F9 - Take screenshot\n");
|
183
|
|
- printf("F11 - Set window to 640x460\n");
|
184
|
|
- printf("F11 - Set window to 800x600\n");
|
185
|
|
- printf("F12 - Set window to 1024x768\n");
|
186
|
|
- printf("ALT+ENTER - Toogle fullscreen\n");
|
187
|
|
- printf("UP/DOWN - Adjust scene pitch\n");
|
188
|
|
- printf("RIGHT/LEFT - Adjust scene yaw\n");
|
189
|
|
- printf("-/= - Adjust model scaling\n");
|
190
|
|
- printf("----------------------------------\n");
|
191
|
|
- printf("i,k,j,l - Move light\n");
|
192
|
|
- printf("h - Help\n");
|
193
|
|
- default:
|
194
|
|
- handleKey(key);
|
195
|
|
- }
|
196
|
|
-}
|
197
|
|
-
|
198
|
|
-
|
199
|
|
-///////////////////////////////////////////////////
|
200
|
|
-
|
201
|
|
-SDL_Surface *gSDLWindow = NULL;
|
202
|
|
-
|
203
|
|
-
|
204
|
|
-void updateWindowTitle(char *newTitle)
|
205
|
|
-{
|
206
|
|
- static char title[64];
|
207
|
|
-
|
208
|
|
- memcpy(title, newTitle, 64);
|
209
|
|
- title[63] = 0;
|
210
|
|
-
|
211
|
|
- SDL_WM_SetCaption(title, "PSKModel.test");
|
212
|
|
-}
|
213
|
|
-
|
214
|
|
-
|
215
|
|
-unsigned int getTicks()
|
216
|
|
-{
|
217
|
|
- return SDL_GetTicks();
|
218
|
|
-}
|
219
|
|
-
|
220
|
|
-
|
221
|
|
-void swap_buffers()
|
222
|
|
-{
|
223
|
|
- SDL_GL_SwapBuffers();
|
224
|
|
-}
|
225
|
|
-
|
226
|
|
-
|
227
|
|
-void event_resize(unsigned int width, unsigned int height)
|
228
|
|
-{
|
229
|
|
- GLfloat aspect;
|
230
|
|
-
|
231
|
|
-
|
232
|
|
- gWidth = width;
|
233
|
|
- gHeight = height;
|
234
|
|
-
|
235
|
|
- aspect = (GLfloat)width/(GLfloat)height;
|
236
|
|
-
|
237
|
|
- glViewport(0, 0, width, height);
|
238
|
|
-
|
239
|
|
- glMatrixMode(GL_PROJECTION);
|
240
|
|
- glLoadIdentity();
|
241
|
|
- gluPerspective(45.0f, aspect, 8.0f, 4600.0f);
|
242
|
|
-
|
243
|
|
- glMatrixMode(GL_MODELVIEW);
|
244
|
|
- glLoadIdentity();
|
245
|
|
-
|
246
|
|
- // Resize window
|
247
|
|
- gSDLWindow = SDL_SetVideoMode(width, height, 16, SDL_OPENGL);
|
248
|
|
-}
|
249
|
|
-
|
250
|
|
-
|
251
|
|
-#ifdef FIXME
|
252
|
|
-void draw_axis(float length, float arrowLenght)
|
253
|
|
-{
|
254
|
|
- /* Draw axis list to show bone orientation */
|
255
|
|
- glBegin(GL_LINES);
|
256
|
|
-
|
257
|
|
- /* X axis */
|
258
|
|
- glColor3f(1.0f, 0.0f, 0.0f);
|
259
|
|
- glVertex3f(-8.0f, 0.0f, 0.0f);
|
260
|
|
- glVertex3f(8.0f, 0.0f, 0.0f);
|
261
|
|
-
|
262
|
|
- /* X direction */
|
263
|
|
- glVertex3f(8.0f, 0.0f, 0.0f);
|
264
|
|
- glVertex3f(7.0f, 1.0f, 0.0f);
|
265
|
|
- glVertex3f(8.0f, 0.0f, 0.0f);
|
266
|
|
- glVertex3f(7.0f, -1.0f, 0.0f);
|
267
|
|
-
|
268
|
|
- /* Y axis */
|
269
|
|
- glColor3f(0.0f, 1.0f, 0.0f);
|
270
|
|
- glVertex3f(0.0f, -8.0f, 0.0f);
|
271
|
|
- glVertex3f(0.0f, 8.0f, 0.0f);
|
272
|
|
-
|
273
|
|
- /* Y direction */
|
274
|
|
- glVertex3f(0.0f, 8.0f, 0.0f);
|
275
|
|
- glVertex3f(0.0f, 7.0f, 1.0f);
|
276
|
|
- glVertex3f(0.0f, 8.0f, 0.0f);
|
277
|
|
- glVertex3f(0.0f, 7.0f, -1.0f);
|
278
|
|
-
|
279
|
|
- /* Z axis */
|
280
|
|
- glColor3f(0.0f, 0.0f, 1.0f);
|
281
|
|
- glVertex3f(0.0f, 0.0f, -8.0f);
|
282
|
|
- glVertex3f(0.0f, 0.0f, 8.0f);
|
283
|
|
-
|
284
|
|
- /* Z direction */
|
285
|
|
- glVertex3f(0.0f, 0.0f, 8.0f);
|
286
|
|
- glVertex3f(0.0f, 1.0f, 7.0f);
|
287
|
|
- glVertex3f(0.0f, 0.0f, 8.0f);
|
288
|
|
- glVertex3f(0.0f, -1.0f, 7.0f);
|
289
|
|
-
|
290
|
|
- glEnd();
|
291
|
|
-}
|
292
|
|
-#endif
|
293
|
|
-
|
294
|
|
-
|
295
|
|
-void renderUnitTestScene()
|
296
|
|
-{
|
297
|
|
-
|
298
|
|
- static float lastTime = 0.0f;
|
299
|
|
- const float size = 500.0f, step = 50.0f;
|
300
|
|
- float x, y, time;
|
301
|
|
-
|
302
|
|
-
|
303
|
|
- gluLookAt(0.0, 0.0, -256.0,
|
304
|
|
- 0.0, 8.0, 0.0,
|
305
|
|
- 0.0, 1.0, 0.0);
|
306
|
|
-
|
307
|
|
- glDisable(GL_TEXTURE_2D);
|
308
|
|
-
|
309
|
|
- time = getTicks() * 0.1f;
|
310
|
|
-
|
311
|
|
- if (time - lastTime > 5.0f)
|
312
|
|
- {
|
313
|
|
- lastTime = time;
|
314
|
|
-
|
315
|
|
- if (gYawOn)
|
316
|
|
- ++gYaw;
|
317
|
|
- }
|
318
|
|
-
|
319
|
|
-#ifdef DRAW_ACTUAL_ORIGIN_AXIS_WITH_ROTATION
|
320
|
|
- glPushMatrix();
|
321
|
|
- glRotatef(yaw, 0, 1, 0);
|
322
|
|
- glBegin(GL_LINES);
|
323
|
|
- glColor3f(1.0f, 0.0f, 0.0f);
|
324
|
|
- glVertex3f(0.0f, 0.0f, 0.0f);
|
325
|
|
- glVertex3f(10.0f, 0.0f, 0.0f);
|
326
|
|
- glColor3f(0.0f, 1.0f, 0.0f);
|
327
|
|
- glVertex3f(0.0f, 0.0f, 0.0f);
|
328
|
|
- glVertex3f(0.0f, 10.0f, 0.0f);
|
329
|
|
- glColor3f(0.0f, 0.0f, 1.0f);
|
330
|
|
- glVertex3f(0.0f, 0.0f, 0.0f);
|
331
|
|
- glVertex3f(0.0f, 0.0f, 10.0f);
|
332
|
|
- glEnd();
|
333
|
|
- glPopMatrix();
|
334
|
|
-#endif
|
335
|
|
-
|
336
|
|
- // Draw light symbol
|
337
|
|
- glPushMatrix();
|
338
|
|
- glTranslatef(gLightPos[0], gLightPos[1], gLightPos[2]);
|
339
|
|
-
|
340
|
|
- glBegin(GL_LINES);
|
341
|
|
- glColor3f(1.0f, 1.0f, 1.0f);
|
342
|
|
- glVertex3f(0.0f, 0.0f, 0.0f);
|
343
|
|
- glVertex3f(10.0f, 0.0f, 0.0f);
|
344
|
|
- glVertex3f(0.0f, 0.0f, 0.0f);
|
345
|
|
- glVertex3f(0.0f, 10.0f, 0.0f);
|
346
|
|
- glVertex3f(0.0f, 0.0f, 0.0f);
|
347
|
|
- glVertex3f(0.0f, 0.0f, 10.0f);
|
348
|
|
- glEnd();
|
349
|
|
- glPopMatrix();
|
350
|
|
-
|
351
|
|
- glTranslatef(0.0f, -128.0f, 512.0f);
|
352
|
|
- glRotatef(gPitch, 1, 0, 0);
|
353
|
|
- glRotatef(gYaw, 0, 1, 0);
|
354
|
|
-
|
355
|
|
- // Draw transformed origin axis
|
356
|
|
- glBegin(GL_LINES);
|
357
|
|
- glColor3f(1.0f, 0.0f, 0.0f);
|
358
|
|
- glVertex3f(-30.0f, 0.0f, 0.0f);
|
359
|
|
- glVertex3f(30.0f, 0.0f, 0.0f);
|
360
|
|
- glColor3f(0.0f, 1.0f, 0.0f);
|
361
|
|
- glVertex3f(0.0f, -30.0f, 0.0f);
|
362
|
|
- glVertex3f(0.0f, 30.0f, 0.0f);
|
363
|
|
- glColor3f(0.0f, 0.0f, 1.0f);
|
364
|
|
- glVertex3f(0.0f, 0.0f, -30.0f);
|
365
|
|
- glVertex3f(0.0f, 0.0f, 30.0f);
|
366
|
|
- glEnd();
|
367
|
|
-
|
368
|
|
- // Draw grid
|
369
|
|
- glPushMatrix();
|
370
|
|
- glScalef(2.0f, 2.0f, 2.0f);
|
371
|
|
- glColor3f(0.4f, 0.4f, 0.6f);
|
372
|
|
-
|
373
|
|
- for (x = -size; x < size; x += step)
|
374
|
|
- {
|
375
|
|
- glBegin(GL_LINE_LOOP);
|
376
|
|
- for (y = -size; y < size; y += step)
|
377
|
|
- {
|
378
|
|
- glVertex3f(x + step, 0.0f, y);
|
379
|
|
- glVertex3f(x, 0.0f, y);
|
380
|
|
- glVertex3f(x, 0.0f, y + step);
|
381
|
|
- glVertex3f(x + step, 0.0f, y + step);
|
382
|
|
- }
|
383
|
|
- glEnd();
|
384
|
|
- }
|
385
|
|
-
|
386
|
|
- glPopMatrix();
|
387
|
|
-
|
388
|
|
-
|
389
|
|
- glEnable(GL_TEXTURE_2D);
|
390
|
|
- glColor3f(1.0f, 1.0f, 1.0f);
|
391
|
|
- glPushMatrix();
|
392
|
|
- glTranslatef(0.0f, 8.0f, 0.0f);
|
393
|
|
- glScalef(gScale, gScale, gScale);
|
394
|
|
-
|
395
|
|
- renderScene(time, lastTime);
|
396
|
|
-
|
397
|
|
- glPopMatrix();
|
398
|
|
-}
|
399
|
|
-
|
400
|
|
-
|
401
|
|
-void event_display(int width, int height)
|
402
|
|
-{
|
403
|
|
- glClearColor(0.3, 0.3, 0.5, 1.0);
|
404
|
|
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
405
|
|
- glLoadIdentity();
|
406
|
|
-
|
407
|
|
- renderUnitTestScene();
|
408
|
|
-
|
409
|
|
- glFlush();
|
410
|
|
- swap_buffers();
|
411
|
|
-}
|
412
|
|
-
|
413
|
|
-
|
414
|
|
-void shutdown_gl()
|
415
|
|
-{
|
416
|
|
- SDL_Quit();
|
417
|
|
-}
|
418
|
|
-
|
419
|
|
-
|
420
|
|
-void init_gl(unsigned int width, unsigned int height)
|
421
|
|
-{
|
422
|
|
- // Print driver support information
|
423
|
|
- printf("\n\n\t## GL Driver Info ##\n");
|
424
|
|
- printf("\tVendor : %s\n", glGetString(GL_VENDOR));
|
425
|
|
- printf("\tRenderer : %s\n", glGetString(GL_RENDERER));
|
426
|
|
- printf("\tVersion : %s\n", glGetString(GL_VERSION));
|
427
|
|
- printf("\tExtensions : %s\n\n\n", (char*)glGetString(GL_EXTENSIONS));
|
428
|
|
-
|
429
|
|
- // Setup GL
|
430
|
|
- glClearColor(0.3, 0.3, 0.5, 1.0);
|
431
|
|
- event_resize(width, height);
|
432
|
|
-
|
433
|
|
- // Texture setup
|
434
|
|
- //gTexture.reset();
|
435
|
|
- //gTexture.setMaxTextureCount(64);
|
436
|
|
-}
|
437
|
|
-
|
438
|
|
-
|
439
|
|
-int main_gl(int argc, char *argv[])
|
440
|
|
-{
|
441
|
|
- SDL_Event event;
|
442
|
|
- unsigned int mkeys, mod, key, flags;
|
443
|
|
- unsigned int width = gWidth;
|
444
|
|
- unsigned int height = gHeight;
|
445
|
|
- bool fullscreen = false;
|
446
|
|
- char *driver = 0x0;
|
447
|
|
-
|
448
|
|
-
|
449
|
|
- // Setup clean up on exit
|
450
|
|
- atexit(shutdown_gl);
|
451
|
|
-
|
452
|
|
- // NOTE: Removed fullscreen/driver option parser args
|
453
|
|
-
|
454
|
|
- // Create GL context
|
455
|
|
- SDL_Init(SDL_INIT_VIDEO);
|
456
|
|
- printf("\n@Created OpenGL Context...\n");
|
457
|
|
-
|
458
|
|
-#ifndef __APPLE__
|
459
|
|
- if (!driver || !driver[0] || SDL_GL_LoadLibrary(driver) < 0)
|
460
|
|
- {
|
461
|
|
- SDL_ClearError();
|
462
|
|
-
|
463
|
|
- // Fallback 1
|
464
|
|
- if (SDL_GL_LoadLibrary("libGL.so") < 0)
|
465
|
|
- {
|
466
|
|
- SDL_ClearError();
|
467
|
|
-
|
468
|
|
- // Fallback 2
|
469
|
|
- if (SDL_GL_LoadLibrary("libGL.so.1") < 0)
|
470
|
|
- {
|
471
|
|
- fprintf(stderr, "main_gl> SDL_GL_LoadLibrary failed!\n");
|
472
|
|
- fprintf(stderr, "main_gl> Error is [%s].\n", SDL_GetError());
|
473
|
|
- exit(1);
|
474
|
|
- }
|
475
|
|
- }
|
476
|
|
- }
|
477
|
|
-#endif
|
478
|
|
-
|
479
|
|
- flags = SDL_OPENGL;
|
480
|
|
-
|
481
|
|
- if (fullscreen)
|
482
|
|
- {
|
483
|
|
- flags |= SDL_FULLSCREEN;
|
484
|
|
- SDL_ShowCursor(SDL_DISABLE);
|
485
|
|
- }
|
486
|
|
-
|
487
|
|
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
|
488
|
|
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
|
489
|
|
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
|
490
|
|
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
491
|
|
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
492
|
|
- gSDLWindow = SDL_SetVideoMode(width, height, 16, flags);
|
493
|
|
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
494
|
|
-
|
495
|
|
- // Init rendering
|
496
|
|
- init_gl(width, height);
|
497
|
|
- initScene(argc, argv);
|
498
|
|
-
|
499
|
|
- printf("\n@Starting event loop...\n");
|
500
|
|
- updateWindowTitle(argv[0]);
|
501
|
|
-
|
502
|
|
- for (;;)
|
503
|
|
- {
|
504
|
|
- while (SDL_PollEvent(&event))
|
505
|
|
- {
|
506
|
|
- switch (event.type)
|
507
|
|
- {
|
508
|
|
- case SDL_QUIT:
|
509
|
|
- exit(0);
|
510
|
|
- break;
|
511
|
|
- case SDL_MOUSEMOTION:
|
512
|
|
- break;
|
513
|
|
- case SDL_MOUSEBUTTONDOWN:
|
514
|
|
- case SDL_MOUSEBUTTONUP:
|
515
|
|
- break;
|
516
|
|
- case SDL_KEYDOWN:
|
517
|
|
- mkeys = (unsigned int)SDL_GetModState();
|
518
|
|
- mod = 0;
|
519
|
|
-
|
520
|
|
- if (mkeys & KMOD_LSHIFT)
|
521
|
|
- mod |= KMOD_LSHIFT;
|
522
|
|
-
|
523
|
|
- if (mkeys & KMOD_RSHIFT)
|
524
|
|
- mod |= KMOD_RSHIFT;
|
525
|
|
-
|
526
|
|
- if (mkeys & KMOD_LCTRL)
|
527
|
|
- mod |= KMOD_LCTRL;
|
528
|
|
-
|
529
|
|
- if (mkeys & KMOD_RCTRL)
|
530
|
|
- mod |= KMOD_RCTRL;
|
531
|
|
-
|
532
|
|
- if (mkeys & KMOD_LALT)
|
533
|
|
- mod |= KMOD_LALT;
|
534
|
|
-
|
535
|
|
- if (mkeys & KMOD_RALT)
|
536
|
|
- mod |= KMOD_RALT;
|
537
|
|
-
|
538
|
|
- key = event.key.keysym.sym;
|
539
|
|
-
|
540
|
|
- switch (key)
|
541
|
|
- {
|
542
|
|
- case SDLK_ESCAPE: // 0x1B, 27d, ESC
|
543
|
|
- exit(0);
|
544
|
|
- break;
|
545
|
|
- case SDLK_RETURN:
|
546
|
|
- if (mod & KMOD_LALT)
|
547
|
|
- {
|
548
|
|
- SDL_ShowCursor(SDL_DISABLE);
|
549
|
|
- SDL_WM_ToggleFullScreen(gSDLWindow);
|
550
|
|
- }
|
551
|
|
- }
|
552
|
|
-
|
553
|
|
- handle_key(key);
|
554
|
|
- break;
|
555
|
|
- case SDL_KEYUP:
|
556
|
|
- break;
|
557
|
|
- case SDL_VIDEORESIZE:
|
558
|
|
- event_resize(event.resize.w, event.resize.h);
|
559
|
|
-
|
560
|
|
- width = event.resize.w;
|
561
|
|
- height = event.resize.h;
|
562
|
|
- event_display(width, height);
|
563
|
|
- break;
|
564
|
|
- }
|
565
|
|
- }
|
566
|
|
-
|
567
|
|
- event_display(width, height);
|
568
|
|
- }
|
569
|
|
-
|
570
|
|
- return 0;
|
571
|
|
-}
|
572
|
|
-#endif
|
573
|
|
-
|
574
|
|
-
|
575
|
|
-int runSDLUnitTest(int argc, char *argv[])
|
576
|
|
-{
|
577
|
|
- handle_key('h');
|
578
|
|
-
|
579
|
|
- if (argc > 1)
|
580
|
|
- {
|
581
|
|
- for (int i = 0; argv[1][i] != 0; ++i)
|
582
|
|
- {
|
583
|
|
- switch (argv[1][i])
|
584
|
|
- {
|
585
|
|
- default:
|
586
|
|
- handleArgKey(argv[1][i]);
|
587
|
|
- }
|
588
|
|
- }
|
589
|
|
- }
|
590
|
|
- else
|
591
|
|
- {
|
592
|
|
- printf("'%s h' for help\n", argv[0]);
|
593
|
|
- }
|
594
|
|
-
|
595
|
|
-
|
596
|
|
-#ifdef USING_OPENGL
|
597
|
|
- main_gl(argc, argv);
|
598
|
|
-#else
|
599
|
|
- printf("Build not OpenGL enabled\n");
|
600
|
|
-#endif
|
601
|
|
-
|
602
|
|
- return 0;
|
603
|
|
-}
|
604
|
|
-#endif
|