# HG changeset patch # User Matti Hamalainen # Date 1572260906 -7200 # Node ID 89dc8caeff41292a027dc13ae60c18cf56a84cb4 # Parent c6c419861101b16540e82dc6dc09b3b691e2c533 Improve option handling a bit. diff -r c6c419861101 -r 89dc8caeff41 glxdragon.cpp --- 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 #include - -#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 Window width (default %d)\n" + "-h 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 ..