Mercurial > hg > forks > gldragon
comparison glxdragon.cpp @ 11:89dc8caeff41
Improve option handling a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 28 Oct 2019 13:08:26 +0200 |
parents | c6c419861101 |
children | 52a586c344f4 |
comparison
equal
deleted
inserted
replaced
10:c6c419861101 | 11:89dc8caeff41 |
---|---|
37 #include <fstream> | 37 #include <fstream> |
38 #include <string> | 38 #include <string> |
39 #include <vector> | 39 #include <vector> |
40 #include <cstdio> | 40 #include <cstdio> |
41 | 41 |
42 | 42 /* Default settings etc. constants |
43 #define SET_FRAMES (180 * 2) | 43 */ |
44 | 44 #define SET_DEF_WIDTH 1280 |
45 | 45 #define SET_DEF_HEIGHT 960 |
46 bool optUseShaders = false; | 46 #define SET_FRAMES (180 * 2) |
47 SDL_Window *dmWindow = NULL; | 47 |
48 SDL_GLContext dmGLContext = NULL; | 48 |
49 | 49 /* Structures |
50 | 50 */ |
51 struct Mesh | 51 struct Mesh |
52 { | 52 { |
53 int nvertices, nfaces; | 53 int nvertices, nfaces; |
54 std::vector<float> vertices; | 54 std::vector<float> vertices; |
55 std::vector<unsigned> faces; | 55 std::vector<unsigned> faces; |
56 | 56 |
57 GLuint id_prog, id_ps, id_vs; | 57 GLuint id_prog, id_ps, id_vs; |
58 }; | 58 }; |
59 | 59 |
60 | |
61 | |
62 /* Options | |
63 */ | |
64 bool optUseShaders = false; | |
65 int optWidth = SET_DEF_WIDTH, | |
66 optHeight = SET_DEF_HEIGHT; | |
67 | |
68 | |
69 /* Globals | |
70 */ | |
71 SDL_Window *dmWindow = NULL; | |
72 SDL_GLContext dmGLContext = NULL; | |
60 | 73 |
61 | 74 |
62 bool dmInitSDLGL(const int width, const int height, const char *title) | 75 bool dmInitSDLGL(const int width, const int height, const char *title) |
63 { | 76 { |
64 // Set GL attributes | 77 // Set GL attributes |
294 std::string dragonVS, dragonFS; | 307 std::string dragonVS, dragonFS; |
295 bool exitFlag = false, optShowHelp = false; | 308 bool exitFlag = false, optShowHelp = false; |
296 int startTime, nframes = 0; | 309 int startTime, nframes = 0; |
297 | 310 |
298 // Check commandline argument for enabling shaders | 311 // Check commandline argument for enabling shaders |
299 | |
300 for (int narg = 1; narg < argc; narg++) | 312 for (int narg = 1; narg < argc; narg++) |
301 { | 313 { |
302 char *arg = argv[narg]; | 314 char *arg = argv[narg]; |
303 if (strstr(arg, "help") != NULL || | 315 if (arg[0] == '-') |
304 strstr(arg, "?") != NULL) | 316 { |
305 optShowHelp = true; | 317 char *opt = arg + 1; |
306 else | 318 |
307 if (strstr(arg, "glsl") != NULL || | 319 if ((opt[0] == '-' && opt[1] == 'h' && opt[2] == 'e') || |
308 strstr(arg, "sha") != NULL) | 320 opt[0] == '?') |
309 optUseShaders = true; | 321 { |
322 optShowHelp = true; | |
323 break; | |
324 } | |
325 else | |
326 if (opt[0] == '-') | |
327 opt++; | |
328 | |
329 if (opt[0] == 'g') | |
330 optUseShaders = true; | |
331 else | |
332 if (opt[0] == 'w') | |
333 optWidth = atoi(opt + 1); | |
334 else | |
335 if (opt[0] == 'h') | |
336 optHeight = atoi(opt + 1); | |
337 } | |
310 } | 338 } |
311 | 339 |
312 if (optShowHelp) | 340 if (optShowHelp) |
313 { | 341 { |
314 printf( | 342 printf( |
315 "Usage: %s [glsl]\n" | 343 "Usage: %s [options]\n" |
316 "glsl argument will turn on GLSL shader mode instead of basic OpenGL lighting.\n" | 344 "-? Show this help\n" |
317 , argv[0]); | 345 "-g Use GLSL shader instead of basic OpenGL lighting\n" |
346 "-w<width> Window width (default %d)\n" | |
347 "-h<height> Window height (default %d)\n" | |
348 "\n", | |
349 argv[0], | |
350 SET_DEF_WIDTH, SET_DEF_HEIGHT | |
351 ); | |
352 | |
318 goto exit; | 353 goto exit; |
319 } | 354 } |
320 | 355 |
321 if (!dmLoadMesh("dragon.mesh", dragonMesh, 100139, 200198)) | 356 if (!dmLoadMesh("dragon.mesh", dragonMesh, 100139, 200198)) |
322 goto exit; | 357 goto exit; |
328 !dmReadText("dragon.vert", dragonVS)) | 363 !dmReadText("dragon.vert", dragonVS)) |
329 goto exit; | 364 goto exit; |
330 } | 365 } |
331 | 366 |
332 // Initialize SDL + OpenGL | 367 // Initialize SDL + OpenGL |
333 if (!dmInitSDLGL(1280, 960, "GLXDragon2")) | 368 if (!dmInitSDLGL(optWidth, optHeight, "GLXDragon2")) |
334 goto exit; | 369 goto exit; |
335 | 370 |
336 // According to our mode .. | 371 // According to our mode .. |
337 if (optUseShaders) | 372 if (optUseShaders) |
338 { | 373 { |