options/config
[demo_prior] / src / main.c
index 2113a53..a6db187 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include "miniglut.h"
 #include "demo.h"
+#include "opt.h"
 
 static void display(void);
 static void idle(void);
@@ -12,10 +13,20 @@ static long time_start;
 
 int main(int argc, char **argv)
 {
+       unsigned int glut_flags = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;
+
        glutInit(&argc, argv);
-       glutInitWindowSize(1280, 800);
-       glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_SRGB | GLUT_MULTISAMPLE);
-       glutCreateWindow("demo");
+
+       read_cfg("demo.cfg");
+       if(parse_args(argc, argv) == -1) {
+               return 1;
+       }
+       if(opt.srgb) glut_flags |= GLUT_SRGB;
+       if(opt.msaa) glut_flags |= GLUT_MULTISAMPLE;
+
+       glutInitWindowSize(opt.width, opt.height);
+       glutInitDisplayMode(glut_flags);
+       glutCreateWindow("Prior Art / Mindlapse");
 
        glutDisplayFunc(display);
        glutIdleFunc(idle);
@@ -28,6 +39,10 @@ int main(int argc, char **argv)
        glutSpaceballRotateFunc(demo_sball_rotate);
        glutSpaceballButtonFunc(demo_sball_button);
 
+       if(opt.fullscr) {
+               glutFullScreen();
+       }
+
        if(demo_init() == -1) {
                return 1;
        }
@@ -58,8 +73,26 @@ static void idle(void)
        glutPostRedisplay();
 }
 
+#define KEYCOMBO_FS \
+       ((key == '\r' || key == '\n') && (glutGetModifiers() & GLUT_ACTIVE_ALT))
+
+
 static void keydown(unsigned char key, int x, int y)
 {
+       static int fullscr = -1, prev_x, prev_y;
+
+       if(KEYCOMBO_FS) {
+               if(fullscr == -1) fullscr = opt.fullscr;
+               fullscr ^= 1;
+               if(fullscr) {
+                       prev_x = glutGet(GLUT_WINDOW_X);
+                       prev_y = glutGet(GLUT_WINDOW_Y);
+                       glutFullScreen();
+               } else {
+                       glutPositionWindow(prev_x, prev_y);
+               }
+       }
+
        demo_keyboard(key, 1);
 }