rev |
line source |
nuclear@0
|
1 #include <stdio.h>
|
nuclear@0
|
2 #include <stdlib.h>
|
nuclear@1
|
3 #include <assert.h>
|
nuclear@0
|
4 #include "opengl.h"
|
nuclear@0
|
5 #include "game.h"
|
nuclear@0
|
6 #include "opt.h"
|
nuclear@0
|
7
|
nuclear@0
|
8 static void disp();
|
nuclear@1
|
9 static void idle();
|
nuclear@0
|
10 static void reshape(int x, int y);
|
nuclear@0
|
11 static void keydown(unsigned char key, int x, int y);
|
nuclear@0
|
12 static void keyup(unsigned char key, int x, int y);
|
nuclear@0
|
13 static void skeydown(int key, int x, int y);
|
nuclear@0
|
14 static void skeyup(int key, int x, int y);
|
nuclear@0
|
15 static void mouse(int bn, int state, int x, int y);
|
nuclear@0
|
16 static void motion(int x, int y);
|
nuclear@0
|
17 static void spacemove(int x, int y, int z);
|
nuclear@0
|
18 static void spacerot(int x, int y, int z);
|
nuclear@0
|
19 static void spacebut(int bn, int state);
|
nuclear@0
|
20
|
nuclear@2
|
21 static int centerx, centery;
|
nuclear@1
|
22 static unsigned int prev_msec;
|
nuclear@1
|
23
|
nuclear@2
|
24 static bool stereo_shift_pressed;
|
nuclear@2
|
25
|
nuclear@0
|
26 int main(int argc, char **argv)
|
nuclear@0
|
27 {
|
nuclear@0
|
28 glutInit(&argc, argv);
|
nuclear@0
|
29
|
nuclear@0
|
30 if(!parse_opt(argc, argv)) {
|
nuclear@0
|
31 return 1;
|
nuclear@0
|
32 }
|
nuclear@0
|
33
|
nuclear@0
|
34 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0));
|
nuclear@1
|
35 glutInitWindowSize(opt.xsz, opt.ysz);
|
nuclear@0
|
36 glutCreateWindow("bloboland");
|
nuclear@0
|
37
|
nuclear@0
|
38 glutDisplayFunc(disp);
|
nuclear@1
|
39 glutIdleFunc(idle);
|
nuclear@0
|
40 glutReshapeFunc(reshape);
|
nuclear@0
|
41 glutKeyboardFunc(keydown);
|
nuclear@0
|
42 glutKeyboardUpFunc(keyup);
|
nuclear@0
|
43 glutSpecialFunc(skeydown);
|
nuclear@0
|
44 glutSpecialUpFunc(skeyup);
|
nuclear@0
|
45 glutMouseFunc(mouse);
|
nuclear@0
|
46 glutMotionFunc(motion);
|
nuclear@0
|
47 glutSpaceballMotionFunc(spacemove);
|
nuclear@0
|
48 glutSpaceballRotateFunc(spacerot);
|
nuclear@0
|
49 glutSpaceballButtonFunc(spacebut);
|
nuclear@0
|
50
|
nuclear@0
|
51 glewInit();
|
nuclear@0
|
52
|
nuclear@0
|
53 if(!game_init()) {
|
nuclear@0
|
54 return 1;
|
nuclear@0
|
55 }
|
nuclear@0
|
56
|
nuclear@0
|
57 glutMainLoop();
|
nuclear@0
|
58 }
|
nuclear@0
|
59
|
nuclear@0
|
60 static void disp()
|
nuclear@0
|
61 {
|
nuclear@0
|
62 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
|
nuclear@0
|
63 game_iter((msec - prev_msec) / 1000.0);
|
nuclear@2
|
64 prev_msec = msec;
|
nuclear@0
|
65
|
nuclear@0
|
66
|
nuclear@1
|
67 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
nuclear@0
|
68
|
nuclear@0
|
69 game_render();
|
nuclear@0
|
70
|
nuclear@0
|
71 glutSwapBuffers();
|
nuclear@1
|
72 assert(glGetError() == GL_NO_ERROR);
|
nuclear@1
|
73 }
|
nuclear@1
|
74
|
nuclear@1
|
75 static void idle()
|
nuclear@1
|
76 {
|
nuclear@1
|
77 glutPostRedisplay();
|
nuclear@0
|
78 }
|
nuclear@0
|
79
|
nuclear@0
|
80 static void reshape(int x, int y)
|
nuclear@0
|
81 {
|
nuclear@0
|
82 glViewport(0, 0, x, y);
|
nuclear@0
|
83
|
nuclear@0
|
84 glMatrixMode(GL_PROJECTION);
|
nuclear@0
|
85 glLoadIdentity();
|
nuclear@0
|
86 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
|
nuclear@1
|
87
|
nuclear@1
|
88 win_xsz = x;
|
nuclear@1
|
89 win_ysz = y;
|
nuclear@1
|
90
|
nuclear@1
|
91 centerx = x / 2;
|
nuclear@1
|
92 centery = y / 2;
|
nuclear@0
|
93 }
|
nuclear@0
|
94
|
nuclear@0
|
95 static void keydown(unsigned char key, int x, int y)
|
nuclear@0
|
96 {
|
nuclear@0
|
97 skeydown(key, x, y);
|
nuclear@0
|
98 }
|
nuclear@0
|
99
|
nuclear@0
|
100 static void keyup(unsigned char key, int x, int y)
|
nuclear@0
|
101 {
|
nuclear@0
|
102 skeyup(key, x, y);
|
nuclear@0
|
103 }
|
nuclear@0
|
104
|
nuclear@0
|
105 static void skeydown(int key, int x, int y)
|
nuclear@0
|
106 {
|
nuclear@2
|
107 switch(key) {
|
nuclear@2
|
108 case 27:
|
nuclear@0
|
109 exit(0);
|
nuclear@2
|
110
|
nuclear@2
|
111 case 'z':
|
nuclear@2
|
112 case 'Z':
|
nuclear@2
|
113 stereo_shift_pressed = true;
|
nuclear@2
|
114 break;
|
nuclear@0
|
115 }
|
nuclear@0
|
116
|
nuclear@1
|
117 if(key < GAME_MAX_KEYS) {
|
nuclear@0
|
118 keystate[key] = true;
|
nuclear@0
|
119 }
|
nuclear@0
|
120 }
|
nuclear@0
|
121
|
nuclear@0
|
122 static void skeyup(int key, int x, int y)
|
nuclear@0
|
123 {
|
nuclear@2
|
124 switch(key) {
|
nuclear@2
|
125 case 'z':
|
nuclear@2
|
126 case 'Z':
|
nuclear@2
|
127 stereo_shift_pressed = false;
|
nuclear@2
|
128 break;
|
nuclear@2
|
129 }
|
nuclear@2
|
130
|
nuclear@1
|
131 if(key < GAME_MAX_KEYS) {
|
nuclear@0
|
132 keystate[key] = false;
|
nuclear@0
|
133 }
|
nuclear@0
|
134 }
|
nuclear@0
|
135
|
nuclear@1
|
136
|
nuclear@1
|
137 static int prev_x, prev_y;
|
nuclear@1
|
138
|
nuclear@0
|
139 static void mouse(int bn, int state, int x, int y)
|
nuclear@0
|
140 {
|
nuclear@1
|
141 int idx = bn - GLUT_LEFT_BUTTON;
|
nuclear@1
|
142
|
nuclear@1
|
143 if(idx < GAME_MAX_BUTTONS) {
|
nuclear@1
|
144 bnstate[idx] = state == GLUT_DOWN;
|
nuclear@1
|
145
|
nuclear@1
|
146 if(state == GLUT_DOWN) {
|
nuclear@1
|
147 game_input_shoot(idx);
|
nuclear@1
|
148 }
|
nuclear@1
|
149 }
|
nuclear@1
|
150 prev_x = x;
|
nuclear@1
|
151 prev_y = y;
|
nuclear@0
|
152 }
|
nuclear@0
|
153
|
nuclear@1
|
154
|
nuclear@0
|
155 static void motion(int x, int y)
|
nuclear@0
|
156 {
|
nuclear@1
|
157 /*
|
nuclear@1
|
158 int dx = x - centerx;
|
nuclear@1
|
159 int dy = y - centery;
|
nuclear@1
|
160
|
nuclear@1
|
161 if(!dx && !dy) {
|
nuclear@1
|
162 return;
|
nuclear@1
|
163 }
|
nuclear@1
|
164 game_input_rot(dx * 0.5, dy * 0.5);
|
nuclear@1
|
165
|
nuclear@1
|
166 glutWarpPointer(centerx, centery);
|
nuclear@1
|
167 */
|
nuclear@1
|
168 int dx = x - prev_x;
|
nuclear@1
|
169 int dy = y - prev_y;
|
nuclear@1
|
170
|
nuclear@1
|
171 prev_x = x;
|
nuclear@1
|
172 prev_y = y;
|
nuclear@1
|
173
|
nuclear@2
|
174 if(stereo_shift_pressed) {
|
nuclear@2
|
175 if(dy != 0) {
|
nuclear@2
|
176 stereo_focus_dist += dy * 0.01;
|
nuclear@2
|
177 stereo_eye_sep = stereo_focus_dist / 30.0;
|
nuclear@2
|
178 printf("foc: %f, sep: %f\n", stereo_focus_dist, stereo_eye_sep);
|
nuclear@2
|
179 }
|
nuclear@2
|
180 return;
|
nuclear@2
|
181 }
|
nuclear@2
|
182
|
nuclear@1
|
183 if(bnstate[0]) {
|
nuclear@1
|
184 game_input_rot((float)dx / win_xsz, (float)dy / win_ysz);
|
nuclear@1
|
185 }
|
nuclear@0
|
186 }
|
nuclear@0
|
187
|
nuclear@0
|
188 static void spacemove(int x, int y, int z)
|
nuclear@0
|
189 {
|
nuclear@2
|
190 game_input_move(x * 0.0025, y * 0.0025, -z * 0.0025);
|
nuclear@0
|
191 }
|
nuclear@0
|
192
|
nuclear@0
|
193 static void spacerot(int x, int y, int z)
|
nuclear@0
|
194 {
|
nuclear@2
|
195 game_input_rot(-y * 0.0001, -x * 0.0001);
|
nuclear@0
|
196 }
|
nuclear@0
|
197
|
nuclear@0
|
198 static void spacebut(int bn, int state)
|
nuclear@0
|
199 {
|
nuclear@1
|
200 game_input_shoot(bn);
|
nuclear@0
|
201 }
|