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