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@2
|
20 int main(int argc, char **argv)
|
nuclear@2
|
21 {
|
nuclear@2
|
22 glutInitWindowSize(1024, 600);
|
nuclear@2
|
23 glutInit(&argc, argv);
|
nuclear@2
|
24 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
|
nuclear@2
|
25 glutCreateWindow("VR Chess");
|
nuclear@2
|
26
|
nuclear@2
|
27 glutDisplayFunc(display);
|
nuclear@2
|
28 glutIdleFunc(idle);
|
nuclear@2
|
29 glutReshapeFunc(reshape);
|
nuclear@2
|
30 glutKeyboardFunc(keyb);
|
nuclear@2
|
31 glutKeyboardUpFunc(keyb_up);
|
nuclear@2
|
32 glutMouseFunc(mouse);
|
nuclear@2
|
33 glutMotionFunc(motion);
|
nuclear@2
|
34 glutSpaceballMotionFunc(sball_motion);
|
nuclear@2
|
35 glutSpaceballRotateFunc(sball_rotate);
|
nuclear@2
|
36
|
nuclear@2
|
37 if(!init()) {
|
nuclear@2
|
38 return 1;
|
nuclear@2
|
39 }
|
nuclear@2
|
40 atexit(cleanup);
|
nuclear@2
|
41
|
nuclear@2
|
42 glutMainLoop();
|
nuclear@2
|
43 return 0;
|
nuclear@2
|
44 }
|
nuclear@2
|
45
|
nuclear@2
|
46 static bool init()
|
nuclear@2
|
47 {
|
nuclear@2
|
48 glewInit();
|
nuclear@2
|
49
|
nuclear@2
|
50 if(!game_init()) {
|
nuclear@2
|
51 return false;
|
nuclear@2
|
52 }
|
nuclear@7
|
53
|
nuclear@7
|
54 int win_xsz = vr_get_opti(VR_OPT_DISPLAY_WIDTH);
|
nuclear@7
|
55 int win_ysz = vr_get_opti(VR_OPT_DISPLAY_HEIGHT);
|
nuclear@7
|
56 if(win_xsz && win_ysz) {
|
nuclear@7
|
57 glutReshapeWindow(win_xsz, win_ysz);
|
nuclear@7
|
58 }
|
nuclear@2
|
59 return true;
|
nuclear@2
|
60 }
|
nuclear@2
|
61
|
nuclear@2
|
62 static void cleanup()
|
nuclear@2
|
63 {
|
nuclear@2
|
64 game_cleanup();
|
nuclear@2
|
65 }
|
nuclear@2
|
66
|
nuclear@2
|
67 static void display()
|
nuclear@2
|
68 {
|
nuclear@2
|
69 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
|
nuclear@2
|
70
|
nuclear@2
|
71 game_update(msec);
|
nuclear@7
|
72 game_render();
|
nuclear@2
|
73
|
nuclear@6
|
74 if(!vr_swap_buffers()) {
|
nuclear@6
|
75 glutSwapBuffers();
|
nuclear@6
|
76 }
|
nuclear@2
|
77 }
|
nuclear@2
|
78
|
nuclear@2
|
79 static void idle()
|
nuclear@2
|
80 {
|
nuclear@2
|
81 glutPostRedisplay();
|
nuclear@2
|
82 }
|
nuclear@2
|
83
|
nuclear@2
|
84 static void reshape(int x, int y)
|
nuclear@2
|
85 {
|
nuclear@2
|
86 game_reshape(x, y);
|
nuclear@2
|
87 }
|
nuclear@2
|
88
|
nuclear@2
|
89 static void keyb(unsigned char key, int x, int y)
|
nuclear@2
|
90 {
|
nuclear@2
|
91 game_keyboard(key, true, x, y);
|
nuclear@2
|
92 }
|
nuclear@2
|
93
|
nuclear@2
|
94 static void keyb_up(unsigned char key, int x, int y)
|
nuclear@2
|
95 {
|
nuclear@2
|
96 game_keyboard(key, false, x, y);
|
nuclear@2
|
97 }
|
nuclear@2
|
98
|
nuclear@2
|
99 static void mouse(int bn, int st, int x, int y)
|
nuclear@2
|
100 {
|
nuclear@3
|
101 switch(bn) {
|
nuclear@3
|
102 case GLUT_RIGHT_BUTTON + 1:
|
nuclear@3
|
103 if(st == GLUT_DOWN) {
|
nuclear@3
|
104 game_mwheel(1);
|
nuclear@3
|
105 }
|
nuclear@3
|
106 break;
|
nuclear@3
|
107
|
nuclear@3
|
108 case GLUT_RIGHT_BUTTON + 2:
|
nuclear@3
|
109 if(st == GLUT_DOWN) {
|
nuclear@3
|
110 game_mwheel(-1);
|
nuclear@3
|
111 }
|
nuclear@3
|
112 break;
|
nuclear@3
|
113
|
nuclear@3
|
114 default:
|
nuclear@3
|
115 game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
|
nuclear@3
|
116 }
|
nuclear@2
|
117 }
|
nuclear@2
|
118
|
nuclear@2
|
119 static void motion(int x, int y)
|
nuclear@2
|
120 {
|
nuclear@2
|
121 game_motion(x, y);
|
nuclear@2
|
122 }
|
nuclear@2
|
123
|
nuclear@2
|
124 #define SBALL_MOVE_SCALE 0.00025
|
nuclear@2
|
125 #define SBALL_ROT_SCALE 0.01
|
nuclear@2
|
126
|
nuclear@2
|
127 static void sball_motion(int x, int y, int z)
|
nuclear@2
|
128 {
|
nuclear@2
|
129 game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
|
nuclear@2
|
130 }
|
nuclear@2
|
131
|
nuclear@2
|
132 static void sball_rotate(int x, int y, int z)
|
nuclear@2
|
133 {
|
nuclear@2
|
134 game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
|
nuclear@2
|
135 }
|