rev |
line source |
nuclear@0
|
1 #include <stdio.h>
|
nuclear@0
|
2 #include <stdlib.h>
|
nuclear@0
|
3 #include <unistd.h>
|
nuclear@0
|
4 #include "opengl.h"
|
nuclear@0
|
5 #include "part.h"
|
nuclear@0
|
6 #include "menu_part.h"
|
nuclear@0
|
7 #include "game_part.h"
|
nuclear@0
|
8
|
nuclear@0
|
9 static bool init();
|
nuclear@0
|
10 static void cleanup();
|
nuclear@0
|
11 static void disp();
|
nuclear@0
|
12 static void idle();
|
nuclear@0
|
13 static void reshape(int x, int y);
|
nuclear@0
|
14 static void key_press(unsigned char key, int x, int y);
|
nuclear@0
|
15 static void key_release(unsigned char key, int x, int y);
|
nuclear@0
|
16 static void mouse(int bn, int state, int x, int y);
|
nuclear@0
|
17 static void motion(int x, int y);
|
nuclear@0
|
18 static void sball_motion(int x, int y, int z);
|
nuclear@0
|
19 static void sball_rotate(int x, int y, int z);
|
nuclear@0
|
20 static void sball_button(int bn, int state);
|
nuclear@0
|
21
|
nuclear@0
|
22 int main(int argc, char **argv)
|
nuclear@0
|
23 {
|
nuclear@0
|
24 glutInit(&argc, argv);
|
nuclear@1
|
25 glutInitWindowSize(800, 450);
|
nuclear@0
|
26 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STENCIL);
|
nuclear@0
|
27 glutCreateWindow("Foo");
|
nuclear@0
|
28
|
nuclear@0
|
29 glutDisplayFunc(disp);
|
nuclear@0
|
30 glutIdleFunc(idle);
|
nuclear@0
|
31 glutReshapeFunc(reshape);
|
nuclear@0
|
32 glutKeyboardFunc(key_press);
|
nuclear@0
|
33 glutKeyboardUpFunc(key_release);
|
nuclear@0
|
34 glutMouseFunc(mouse);
|
nuclear@0
|
35 glutMotionFunc(motion);
|
nuclear@0
|
36 glutPassiveMotionFunc(motion);
|
nuclear@0
|
37 glutSpaceballMotionFunc(sball_motion);
|
nuclear@0
|
38 glutSpaceballRotateFunc(sball_rotate);
|
nuclear@0
|
39 glutSpaceballButtonFunc(sball_button);
|
nuclear@0
|
40
|
nuclear@0
|
41 if(!init()) {
|
nuclear@0
|
42 return 1;
|
nuclear@0
|
43 }
|
nuclear@0
|
44 atexit(cleanup);
|
nuclear@0
|
45
|
nuclear@0
|
46 glutMainLoop();
|
nuclear@0
|
47 return 0;
|
nuclear@0
|
48 }
|
nuclear@0
|
49
|
nuclear@0
|
50
|
nuclear@0
|
51 static bool init()
|
nuclear@0
|
52 {
|
nuclear@0
|
53 glewInit();
|
nuclear@0
|
54
|
nuclear@0
|
55 menu_part = new MainMenu;
|
nuclear@2
|
56 if(!menu_part->init()) {
|
nuclear@2
|
57 return false;
|
nuclear@2
|
58 }
|
nuclear@2
|
59
|
nuclear@0
|
60 game_part = new Game;
|
nuclear@2
|
61 if(!game_part->init()) {
|
nuclear@2
|
62 return false;
|
nuclear@2
|
63 }
|
nuclear@2
|
64
|
nuclear@0
|
65 cur_part = menu_part;
|
nuclear@0
|
66 return true;
|
nuclear@0
|
67 }
|
nuclear@0
|
68
|
nuclear@0
|
69 static void cleanup()
|
nuclear@0
|
70 {
|
nuclear@0
|
71 delete menu_part;
|
nuclear@0
|
72 delete game_part;
|
nuclear@0
|
73 }
|
nuclear@0
|
74
|
nuclear@0
|
75 static void disp()
|
nuclear@0
|
76 {
|
nuclear@0
|
77 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
|
nuclear@0
|
78 cur_part->update(msec);
|
nuclear@0
|
79 cur_part->draw();
|
nuclear@0
|
80
|
nuclear@0
|
81 glutSwapBuffers();
|
nuclear@0
|
82 usleep(1000);
|
nuclear@0
|
83 }
|
nuclear@0
|
84
|
nuclear@0
|
85 static void idle()
|
nuclear@0
|
86 {
|
nuclear@0
|
87 glutPostRedisplay();
|
nuclear@0
|
88 }
|
nuclear@0
|
89
|
nuclear@0
|
90 static void reshape(int x, int y)
|
nuclear@0
|
91 {
|
nuclear@0
|
92 glViewport(0, 0, x, y);
|
nuclear@0
|
93
|
nuclear@0
|
94 cur_part->reshape(x, y);
|
nuclear@0
|
95 }
|
nuclear@0
|
96
|
nuclear@0
|
97 static void key_press(unsigned char key, int x, int y)
|
nuclear@0
|
98 {
|
nuclear@0
|
99 cur_part->key(key, true);
|
nuclear@0
|
100 }
|
nuclear@0
|
101
|
nuclear@0
|
102 static void key_release(unsigned char key, int x, int y)
|
nuclear@0
|
103 {
|
nuclear@0
|
104 cur_part->key(key, false);
|
nuclear@0
|
105 }
|
nuclear@0
|
106
|
nuclear@0
|
107 static void mouse(int bn, int state, int x, int y)
|
nuclear@0
|
108 {
|
nuclear@0
|
109 cur_part->mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN);
|
nuclear@0
|
110 }
|
nuclear@0
|
111
|
nuclear@0
|
112 static void motion(int x, int y)
|
nuclear@0
|
113 {
|
nuclear@0
|
114 cur_part->mouse_motion(x, y);
|
nuclear@0
|
115 }
|
nuclear@0
|
116
|
nuclear@0
|
117 static int sbmotion[6];
|
nuclear@0
|
118
|
nuclear@0
|
119 static void sball_motion(int x, int y, int z)
|
nuclear@0
|
120 {
|
nuclear@0
|
121 sbmotion[0] = x;
|
nuclear@0
|
122 sbmotion[1] = y;
|
nuclear@0
|
123 sbmotion[2] = z;
|
nuclear@0
|
124 cur_part->spaceball_motion(sbmotion[0], sbmotion[1], sbmotion[2],
|
nuclear@0
|
125 sbmotion[3], sbmotion[4], sbmotion[5]);
|
nuclear@0
|
126 }
|
nuclear@0
|
127
|
nuclear@0
|
128 static void sball_rotate(int x, int y, int z)
|
nuclear@0
|
129 {
|
nuclear@0
|
130 sbmotion[3] = x;
|
nuclear@0
|
131 sbmotion[4] = y;
|
nuclear@0
|
132 sbmotion[5] = z;
|
nuclear@0
|
133 cur_part->spaceball_motion(sbmotion[0], sbmotion[1], sbmotion[2],
|
nuclear@0
|
134 sbmotion[3], sbmotion[4], sbmotion[5]);
|
nuclear@0
|
135 }
|
nuclear@0
|
136
|
nuclear@0
|
137 static void sball_button(int bn, int state)
|
nuclear@0
|
138 {
|
nuclear@0
|
139 cur_part->spaceball_button(bn, state == GLUT_DOWN);
|
nuclear@0
|
140 }
|