17 0.0f // minimum turn angle
33 static optcfg_option options[] = {
34 // short, long, id, desc
35 {'s', "size", OPT_SIZE, "window size (WxH)"},
36 {0, "vr", OPT_VR, "enable VR mode"},
37 {'f', "fullscreen", OPT_FULLSCREEN, "run in fullscreen mode"},
38 {'w', "windowed", OPT_WINDOWED, "run in windowed mode"},
39 {0, "scene", OPT_SCENEFILE, "scene file to open"},
40 {'m', "music", OPT_MUSIC, "play background audio"},
41 {'r', "reflect", OPT_REFLECT, "render reflections"},
42 {0, "url", OPT_DATAURL, "data URL"},
43 {0, "minturn", OPT_MIN_TURN, "minimum turn angle"},
44 {'h', "help", OPT_HELP, "print usage and exit"},
48 static int opt_handler(optcfg *oc, int opt, void *cls);
49 static int arg_handler(optcfg *oc, const char *arg, void *cls);
51 bool init_options(int argc, char **argv, const char *cfgfile)
56 optcfg *oc = optcfg_init(options);
57 optcfg_set_opt_callback(oc, opt_handler, 0);
58 optcfg_set_arg_callback(oc, arg_handler, 0);
61 optcfg_parse_config_file(oc, cfgfile);
64 if(argv && optcfg_parse_args(oc, argc, argv) == -1) {
65 fprintf(stderr, "invalid option\n");
74 static bool is_enabled(optcfg *oc)
77 optcfg_enabled_value(oc, &res);
81 static int opt_handler(optcfg *oc, int optid, void *cls)
86 char *valstr = optcfg_next_value(oc);
87 if(!valstr || sscanf(valstr, "%dx%d", &opt.width, &opt.height) != 2) {
88 fprintf(stderr, "size must be in the form: WIDTHxHEIGHT\n");
95 opt.vr = is_enabled(oc);
99 opt.fullscreen = is_enabled(oc);
103 opt.fullscreen = !is_enabled(oc);
107 opt.scenefile = strdup(optcfg_next_value(oc));
111 opt.music = is_enabled(oc);
115 opt.reflect = is_enabled(oc);
119 opt.data_url = strdup(optcfg_next_value(oc));
125 char *valstr = optcfg_next_value(oc);
127 if(!valstr || sscanf(valstr, "%d", °) != 1) {
128 fprintf(stderr, "minimum turn must be a number >= 0 in degrees\n");
136 printf("Usage: demo [options]\nOptions:\n");
137 optcfg_print_options(oc);
143 static int arg_handler(optcfg *oc, const char *arg, void *cls)
146 fprintf(stderr, "unexpected argument: %s\n", arg);