rev |
line source |
nuclear@2
|
1 #include <stdio.h>
|
nuclear@2
|
2 #include <stdlib.h>
|
nuclear@2
|
3 #include "opengl.h"
|
nuclear@2
|
4 #include "game.h"
|
nuclear@13
|
5 #include "gameopt.h"
|
nuclear@6
|
6 #include "vr/vr.h"
|
nuclear@2
|
7
|
nuclear@2
|
8 static bool init();
|
nuclear@2
|
9 static void cleanup();
|
nuclear@2
|
10
|
nuclear@2
|
11 static void display();
|
nuclear@2
|
12 static void idle();
|
nuclear@2
|
13 static void reshape(int x, int y);
|
nuclear@2
|
14 static void keyb(unsigned char key, int x, int y);
|
nuclear@2
|
15 static void keyb_up(unsigned char key, int x, int y);
|
nuclear@2
|
16 static void mouse(int bn, int st, int x, int y);
|
nuclear@2
|
17 static void motion(int x, int y);
|
nuclear@2
|
18 static void sball_motion(int x, int y, int z);
|
nuclear@2
|
19 static void sball_rotate(int x, int y, int z);
|
nuclear@2
|
20
|
nuclear@12
|
21 static bool fullscreen_pending;
|
nuclear@12
|
22
|
nuclear@2
|
23 int main(int argc, char **argv)
|
nuclear@2
|
24 {
|
nuclear@2
|
25 glutInitWindowSize(1024, 600);
|
nuclear@2
|
26 glutInit(&argc, argv);
|
nuclear@13
|
27
|
nuclear@13
|
28 if(!parse_args(argc, argv)) {
|
nuclear@13
|
29 return 1;
|
nuclear@13
|
30 }
|
nuclear@13
|
31
|
nuclear@13
|
32 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0));
|
nuclear@13
|
33 glutCreateWindow("LD48 #30 - connected worlds");
|
nuclear@2
|
34
|
nuclear@2
|
35 glutDisplayFunc(display);
|
nuclear@2
|
36 glutIdleFunc(idle);
|
nuclear@2
|
37 glutReshapeFunc(reshape);
|
nuclear@2
|
38 glutKeyboardFunc(keyb);
|
nuclear@2
|
39 glutKeyboardUpFunc(keyb_up);
|
nuclear@2
|
40 glutMouseFunc(mouse);
|
nuclear@2
|
41 glutMotionFunc(motion);
|
nuclear@2
|
42 glutSpaceballMotionFunc(sball_motion);
|
nuclear@2
|
43 glutSpaceballRotateFunc(sball_rotate);
|
nuclear@2
|
44
|
nuclear@2
|
45 if(!init()) {
|
nuclear@2
|
46 return 1;
|
nuclear@2
|
47 }
|
nuclear@2
|
48 atexit(cleanup);
|
nuclear@2
|
49
|
nuclear@2
|
50 glutMainLoop();
|
nuclear@2
|
51 return 0;
|
nuclear@2
|
52 }
|
nuclear@2
|
53
|
nuclear@2
|
54 static bool init()
|
nuclear@2
|
55 {
|
nuclear@2
|
56 glewInit();
|
nuclear@2
|
57
|
nuclear@2
|
58 if(!game_init()) {
|
nuclear@2
|
59 return false;
|
nuclear@2
|
60 }
|
nuclear@7
|
61
|
nuclear@13
|
62 if(opt.vr) {
|
nuclear@13
|
63 int win_xsz = vr_get_opti(VR_OPT_DISPLAY_WIDTH);
|
nuclear@13
|
64 int win_ysz = vr_get_opti(VR_OPT_DISPLAY_HEIGHT);
|
nuclear@13
|
65 if(win_xsz && win_ysz) {
|
nuclear@13
|
66 glutReshapeWindow(win_xsz, win_ysz);
|
nuclear@13
|
67 }
|
nuclear@7
|
68 }
|
nuclear@2
|
69 return true;
|
nuclear@2
|
70 }
|
nuclear@2
|
71
|
nuclear@2
|
72 static void cleanup()
|
nuclear@2
|
73 {
|
nuclear@2
|
74 game_cleanup();
|
nuclear@2
|
75 }
|
nuclear@2
|
76
|
nuclear@2
|
77 static void display()
|
nuclear@2
|
78 {
|
nuclear@2
|
79 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
|
nuclear@2
|
80
|
nuclear@2
|
81 game_update(msec);
|
nuclear@7
|
82 game_render();
|
nuclear@2
|
83 }
|
nuclear@2
|
84
|
nuclear@2
|
85 static void idle()
|
nuclear@2
|
86 {
|
nuclear@12
|
87 if(fullscreen_pending) {
|
nuclear@12
|
88 glutFullScreen();
|
nuclear@12
|
89 }
|
nuclear@12
|
90
|
nuclear@2
|
91 glutPostRedisplay();
|
nuclear@2
|
92 }
|
nuclear@2
|
93
|
nuclear@2
|
94 static void reshape(int x, int y)
|
nuclear@2
|
95 {
|
nuclear@2
|
96 game_reshape(x, y);
|
nuclear@2
|
97 }
|
nuclear@2
|
98
|
nuclear@2
|
99 static void keyb(unsigned char key, int x, int y)
|
nuclear@2
|
100 {
|
nuclear@11
|
101 static bool fullscr;
|
nuclear@12
|
102 static int prev_xpos, prev_ypos;
|
nuclear@11
|
103 static int prev_xsz, prev_ysz;
|
nuclear@11
|
104
|
nuclear@11
|
105 switch(key) {
|
nuclear@11
|
106 case 'f':
|
nuclear@11
|
107 fullscr = !fullscr;
|
nuclear@11
|
108 if(fullscr) {
|
nuclear@11
|
109 int xoffs, yoffs;
|
nuclear@11
|
110
|
nuclear@12
|
111 prev_xpos = glutGet(GLUT_WINDOW_X);
|
nuclear@12
|
112 prev_ypos = glutGet(GLUT_WINDOW_Y);
|
nuclear@11
|
113 prev_xsz = glutGet(GLUT_WINDOW_WIDTH);
|
nuclear@11
|
114 prev_ysz = glutGet(GLUT_WINDOW_HEIGHT);
|
nuclear@11
|
115
|
nuclear@11
|
116 xoffs = vr_get_opti(VR_OPT_WIN_XOFFS);
|
nuclear@11
|
117 yoffs = vr_get_opti(VR_OPT_WIN_YOFFS);
|
nuclear@11
|
118 if(xoffs || yoffs) {
|
nuclear@11
|
119 printf("repositioning: %d,%d\n", xoffs, yoffs);
|
nuclear@12
|
120 glutPositionWindow(xoffs, yoffs);
|
nuclear@11
|
121 }
|
nuclear@13
|
122 fullscreen_pending = true;
|
nuclear@11
|
123 } else {
|
nuclear@12
|
124 fullscreen_pending = false;
|
nuclear@12
|
125 glutPositionWindow(prev_xpos, prev_ypos);
|
nuclear@11
|
126 glutReshapeWindow(prev_xsz, prev_ysz);
|
nuclear@11
|
127 }
|
nuclear@11
|
128 break;
|
nuclear@11
|
129 }
|
nuclear@2
|
130 game_keyboard(key, true, x, y);
|
nuclear@2
|
131 }
|
nuclear@2
|
132
|
nuclear@2
|
133 static void keyb_up(unsigned char key, int x, int y)
|
nuclear@2
|
134 {
|
nuclear@2
|
135 game_keyboard(key, false, x, y);
|
nuclear@2
|
136 }
|
nuclear@2
|
137
|
nuclear@2
|
138 static void mouse(int bn, int st, int x, int y)
|
nuclear@2
|
139 {
|
nuclear@3
|
140 switch(bn) {
|
nuclear@3
|
141 case GLUT_RIGHT_BUTTON + 1:
|
nuclear@3
|
142 if(st == GLUT_DOWN) {
|
nuclear@3
|
143 game_mwheel(1);
|
nuclear@3
|
144 }
|
nuclear@3
|
145 break;
|
nuclear@3
|
146
|
nuclear@3
|
147 case GLUT_RIGHT_BUTTON + 2:
|
nuclear@3
|
148 if(st == GLUT_DOWN) {
|
nuclear@3
|
149 game_mwheel(-1);
|
nuclear@3
|
150 }
|
nuclear@3
|
151 break;
|
nuclear@3
|
152
|
nuclear@3
|
153 default:
|
nuclear@3
|
154 game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
|
nuclear@3
|
155 }
|
nuclear@2
|
156 }
|
nuclear@2
|
157
|
nuclear@2
|
158 static void motion(int x, int y)
|
nuclear@2
|
159 {
|
nuclear@2
|
160 game_motion(x, y);
|
nuclear@2
|
161 }
|
nuclear@2
|
162
|
nuclear@2
|
163 #define SBALL_MOVE_SCALE 0.00025
|
nuclear@2
|
164 #define SBALL_ROT_SCALE 0.01
|
nuclear@2
|
165
|
nuclear@2
|
166 static void sball_motion(int x, int y, int z)
|
nuclear@2
|
167 {
|
nuclear@2
|
168 game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
|
nuclear@2
|
169 }
|
nuclear@2
|
170
|
nuclear@2
|
171 static void sball_rotate(int x, int y, int z)
|
nuclear@2
|
172 {
|
nuclear@2
|
173 game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
|
nuclear@2
|
174 }
|