29 static optcfg_option options[] = {
30 // short, long, id, desc
31 {'s', "size", OPT_SIZE, "window size (WxH)"},
32 {0, "vr", OPT_VR, "enable VR mode"},
33 {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
34 {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
35 {0, "scene", OPT_SCENEFILE, "scene file to open"},
36 {'m', "music", OPT_MUSIC, "play background audio"},
37 {'r', "reflect", OPT_REFLECT, "render reflections"},
38 {'h', "help", OPT_HELP, "print usage and exit"},
42 static int opt_handler(optcfg *oc, int opt, void *cls);
43 static int arg_handler(optcfg *oc, const char *arg, void *cls);
45 bool init_options(int argc, char **argv, const char *cfgfile)
50 optcfg *oc = optcfg_init(options);
51 optcfg_set_opt_callback(oc, opt_handler, 0);
52 optcfg_set_arg_callback(oc, arg_handler, 0);
55 optcfg_parse_config_file(oc, cfgfile);
58 if(argv && optcfg_parse_args(oc, argc, argv) == -1) {
59 fprintf(stderr, "invalid option\n");
68 static bool is_enabled(optcfg *oc)
71 optcfg_enabled_value(oc, &res);
75 static int opt_handler(optcfg *oc, int optid, void *cls)
80 char *valstr = optcfg_next_value(oc);
81 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
82 fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
89 opt.vr = is_enabled(oc);
93 opt.fullscreen = is_enabled(oc);
97 opt.fullscreen = !is_enabled(oc);
101 opt.scenefile = strdup(optcfg_next_value(oc));
105 opt.music = is_enabled(oc);
109 opt.reflect = is_enabled(oc);
113 printf("Usage: demo [options]\nOptions:\n");
114 optcfg_print_options(oc);
120 static int arg_handler(optcfg *oc, const char *arg, void *cls)
123 fprintf(stderr, "unexpected argument: %s\n", arg);