Mercurial > hg > forks > gldragon
changeset 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 |
files | glxdragon.cpp |
diffstat | 1 files changed, 54 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/glxdragon.cpp Mon Oct 28 12:59:18 2019 +0200 +++ b/glxdragon.cpp Mon Oct 28 13:08:26 2019 +0200 @@ -39,15 +39,15 @@ #include <vector> #include <cstdio> - -#define SET_FRAMES (180 * 2) +/* Default settings etc. constants + */ +#define SET_DEF_WIDTH 1280 +#define SET_DEF_HEIGHT 960 +#define SET_FRAMES (180 * 2) -bool optUseShaders = false; -SDL_Window *dmWindow = NULL; -SDL_GLContext dmGLContext = NULL; - - +/* Structures + */ struct Mesh { int nvertices, nfaces; @@ -59,6 +59,19 @@ +/* Options + */ +bool optUseShaders = false; +int optWidth = SET_DEF_WIDTH, + optHeight = SET_DEF_HEIGHT; + + +/* Globals + */ +SDL_Window *dmWindow = NULL; +SDL_GLContext dmGLContext = NULL; + + bool dmInitSDLGL(const int width, const int height, const char *title) { // Set GL attributes @@ -296,25 +309,47 @@ int startTime, nframes = 0; // Check commandline argument for enabling shaders - for (int narg = 1; narg < argc; narg++) { char *arg = argv[narg]; - if (strstr(arg, "help") != NULL || - strstr(arg, "?") != NULL) - optShowHelp = true; - else - if (strstr(arg, "glsl") != NULL || - strstr(arg, "sha") != NULL) - optUseShaders = true; + if (arg[0] == '-') + { + char *opt = arg + 1; + + if ((opt[0] == '-' && opt[1] == 'h' && opt[2] == 'e') || + opt[0] == '?') + { + optShowHelp = true; + break; + } + else + if (opt[0] == '-') + opt++; + + if (opt[0] == 'g') + optUseShaders = true; + else + if (opt[0] == 'w') + optWidth = atoi(opt + 1); + else + if (opt[0] == 'h') + optHeight = atoi(opt + 1); + } } if (optShowHelp) { printf( - "Usage: %s [glsl]\n" - "glsl argument will turn on GLSL shader mode instead of basic OpenGL lighting.\n" - , argv[0]); + "Usage: %s [options]\n" + "-? Show this help\n" + "-g Use GLSL shader instead of basic OpenGL lighting\n" + "-w<width> Window width (default %d)\n" + "-h<height> Window height (default %d)\n" + "\n", + argv[0], + SET_DEF_WIDTH, SET_DEF_HEIGHT + ); + goto exit; } @@ -330,7 +365,7 @@ } // Initialize SDL + OpenGL - if (!dmInitSDLGL(1280, 960, "GLXDragon2")) + if (!dmInitSDLGL(optWidth, optHeight, "GLXDragon2")) goto exit; // According to our mode ..