27 static optcfg_option options[] = {
28 // short, long, id, desc
29 {'s', "size", OPT_SIZE, "window size (WxH)"},
30 {0, "vr", OPT_VR, "enable VR mode"},
31 {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
32 {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
33 {0, "scene", OPT_SCENEFILE, "scene file to open"},
34 {'m', "music", OPT_MUSIC, "play background audio"},
35 {'h', "help", OPT_HELP, "print usage and exit"},
39 static int opt_handler(optcfg *oc, int opt, void *cls);
40 static int arg_handler(optcfg *oc, const char *arg, void *cls);
42 bool init_options(int argc, char **argv, const char *cfgfile)
47 optcfg *oc = optcfg_init(options);
48 optcfg_set_opt_callback(oc, opt_handler, 0);
49 optcfg_set_arg_callback(oc, arg_handler, 0);
52 optcfg_parse_config_file(oc, cfgfile);
55 if(argv && optcfg_parse_args(oc, argc, argv) == -1) {
56 fprintf(stderr, "invalid option\n");
65 static bool is_enabled(optcfg *oc)
68 optcfg_enabled_value(oc, &res);
72 static int opt_handler(optcfg *oc, int optid, void *cls)
77 char *valstr = optcfg_next_value(oc);
78 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
79 fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
86 opt.vr = is_enabled(oc);
90 opt.fullscreen = is_enabled(oc);
94 opt.fullscreen = !is_enabled(oc);
98 opt.scenefile = strdup(optcfg_next_value(oc));
102 opt.music = is_enabled(oc);
106 printf("Usage: demo [options]\nOptions:\n");
107 optcfg_print_options(oc);
113 static int arg_handler(optcfg *oc, const char *arg, void *cls)
116 fprintf(stderr, "unexpected argument: %s\n", arg);