31 static optcfg_option options[] = {
32 // short, long, id, desc
33 {'s', "size", OPT_SIZE, "window size (WxH)"},
34 {0, "vr", OPT_VR, "enable VR mode"},
35 {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
36 {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
37 {0, "scene", OPT_SCENEFILE, "scene file to open"},
38 {'m', "music", OPT_MUSIC, "play background audio"},
39 {'r', "reflect", OPT_REFLECT, "render reflections"},
40 {0, "url", OPT_DATAURL, "data URL"},
41 {'h', "help", OPT_HELP, "print usage and exit"},
45 static int opt_handler(optcfg *oc, int opt, void *cls);
46 static int arg_handler(optcfg *oc, const char *arg, void *cls);
48 bool init_options(int argc, char **argv, const char *cfgfile)
53 optcfg *oc = optcfg_init(options);
54 optcfg_set_opt_callback(oc, opt_handler, 0);
55 optcfg_set_arg_callback(oc, arg_handler, 0);
58 optcfg_parse_config_file(oc, cfgfile);
61 if(argv && optcfg_parse_args(oc, argc, argv) == -1) {
62 fprintf(stderr, "invalid option\n");
71 static bool is_enabled(optcfg *oc)
74 optcfg_enabled_value(oc, &res);
78 static int opt_handler(optcfg *oc, int optid, void *cls)
83 char *valstr = optcfg_next_value(oc);
84 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
85 fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
92 opt.vr = is_enabled(oc);
96 opt.fullscreen = is_enabled(oc);
100 opt.fullscreen = !is_enabled(oc);
104 opt.scenefile = strdup(optcfg_next_value(oc));
108 opt.music = is_enabled(oc);
112 opt.reflect = is_enabled(oc);
116 opt.data_url = strdup(optcfg_next_value(oc));
120 printf("Usage: demo [options]\nOptions:\n");
121 optcfg_print_options(oc);
127 static int arg_handler(optcfg *oc, const char *arg, void *cls)
130 fprintf(stderr, "unexpected argument: %s\n", arg);