fixed incorrect checking of the existence of GLX_EXT_swap_control and friends
[demo_prior] / src / main.c
1 #include <stdlib.h>
2 #include "miniglut.h"
3 #include "demo.h"
4 #include "opt.h"
5
6 static void display(void);
7 static void idle(void);
8 static void keydown(unsigned char key, int x, int y);
9 static void keyup(unsigned char key, int x, int y);
10 static void mouse(int bn, int st, int x, int y);
11
12 static long time_start;
13
14 int main(int argc, char **argv)
15 {
16         unsigned int glut_flags = GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH;
17
18         glutInit(&argc, argv);
19
20         read_cfg("demo.cfg");
21         if(parse_args(argc, argv) == -1) {
22                 return 1;
23         }
24         if(opt.srgb) glut_flags |= GLUT_SRGB;
25         if(opt.msaa) glut_flags |= GLUT_MULTISAMPLE;
26
27         glutInitWindowSize(opt.width, opt.height);
28         glutInitDisplayMode(glut_flags);
29         glutCreateWindow("Prior Art / Mindlapse");
30
31         glutDisplayFunc(display);
32         glutIdleFunc(idle);
33         glutReshapeFunc(demo_reshape);
34         glutKeyboardFunc(keydown);
35         glutKeyboardUpFunc(keyup);
36         glutMouseFunc(mouse);
37         glutMotionFunc(demo_mmotion);
38         glutPassiveMotionFunc(demo_mmotion);
39         glutSpaceballMotionFunc(demo_sball_motion);
40         glutSpaceballRotateFunc(demo_sball_rotate);
41         glutSpaceballButtonFunc(demo_sball_button);
42
43         if(opt.fullscr) {
44                 glutFullScreen();
45         }
46
47         if(demo_init() == -1) {
48                 return 1;
49         }
50         atexit(demo_cleanup);
51
52         time_start = glutGet(GLUT_ELAPSED_TIME);
53
54         glutMainLoop();
55         return 0;
56 }
57
58 void demo_quit(void)
59 {
60         glutExit();
61 }
62
63 static void display(void)
64 {
65         time_msec = glutGet(GLUT_ELAPSED_TIME) - time_start;
66
67         demo_display();
68
69         glutSwapBuffers();
70 }
71
72 static void idle(void)
73 {
74         glutPostRedisplay();
75 }
76
77 #define KEYCOMBO_FS \
78         ((key == '\r' || key == '\n') && (glutGetModifiers() & GLUT_ACTIVE_ALT))
79
80
81 static void keydown(unsigned char key, int x, int y)
82 {
83         static int fullscr = -1, prev_x, prev_y;
84
85         if(KEYCOMBO_FS) {
86                 if(fullscr == -1) fullscr = opt.fullscr;
87                 fullscr ^= 1;
88                 if(fullscr) {
89                         prev_x = glutGet(GLUT_WINDOW_X);
90                         prev_y = glutGet(GLUT_WINDOW_Y);
91                         glutFullScreen();
92                 } else {
93                         glutPositionWindow(prev_x, prev_y);
94                 }
95         }
96
97         demo_keyboard(key, 1);
98 }
99
100 static void keyup(unsigned char key, int x, int y)
101 {
102         demo_keyboard(key, 0);
103 }
104
105 static void mouse(int bn, int st, int x, int y)
106 {
107         demo_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
108 }