2113a5372428b44172a833f440af177329085ee1
[demo_prior] / src / main.c
1 #include <stdlib.h>
2 #include "miniglut.h"
3 #include "demo.h"
4
5 static void display(void);
6 static void idle(void);
7 static void keydown(unsigned char key, int x, int y);
8 static void keyup(unsigned char key, int x, int y);
9 static void mouse(int bn, int st, int x, int y);
10
11 static long time_start;
12
13 int main(int argc, char **argv)
14 {
15         glutInit(&argc, argv);
16         glutInitWindowSize(1280, 800);
17         glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_SRGB | GLUT_MULTISAMPLE);
18         glutCreateWindow("demo");
19
20         glutDisplayFunc(display);
21         glutIdleFunc(idle);
22         glutReshapeFunc(demo_reshape);
23         glutKeyboardFunc(keydown);
24         glutKeyboardUpFunc(keyup);
25         glutMouseFunc(mouse);
26         glutMotionFunc(demo_mmotion);
27         glutSpaceballMotionFunc(demo_sball_motion);
28         glutSpaceballRotateFunc(demo_sball_rotate);
29         glutSpaceballButtonFunc(demo_sball_button);
30
31         if(demo_init() == -1) {
32                 return 1;
33         }
34         atexit(demo_cleanup);
35
36         time_start = glutGet(GLUT_ELAPSED_TIME);
37
38         glutMainLoop();
39         return 0;
40 }
41
42 void demo_quit(void)
43 {
44         glutExit();
45 }
46
47 static void display(void)
48 {
49         time_msec = glutGet(GLUT_ELAPSED_TIME) - time_start;
50
51         demo_display();
52
53         glutSwapBuffers();
54 }
55
56 static void idle(void)
57 {
58         glutPostRedisplay();
59 }
60
61 static void keydown(unsigned char key, int x, int y)
62 {
63         demo_keyboard(key, 1);
64 }
65
66 static void keyup(unsigned char key, int x, int y)
67 {
68         demo_keyboard(key, 0);
69 }
70
71 static void mouse(int bn, int st, int x, int y)
72 {
73         demo_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
74 }