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@2
|
5
|
nuclear@2
|
6 static bool init();
|
nuclear@2
|
7 static void cleanup();
|
nuclear@2
|
8
|
nuclear@2
|
9 static void display();
|
nuclear@2
|
10 static void idle();
|
nuclear@2
|
11 static void reshape(int x, int y);
|
nuclear@2
|
12 static void keyb(unsigned char key, int x, int y);
|
nuclear@2
|
13 static void keyb_up(unsigned char key, int x, int y);
|
nuclear@2
|
14 static void mouse(int bn, int st, int x, int y);
|
nuclear@2
|
15 static void motion(int x, int y);
|
nuclear@2
|
16 static void sball_motion(int x, int y, int z);
|
nuclear@2
|
17 static void sball_rotate(int x, int y, int z);
|
nuclear@2
|
18
|
nuclear@2
|
19 int main(int argc, char **argv)
|
nuclear@2
|
20 {
|
nuclear@2
|
21 glutInitWindowSize(1024, 600);
|
nuclear@2
|
22 glutInit(&argc, argv);
|
nuclear@2
|
23 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
|
nuclear@2
|
24 glutCreateWindow("VR Chess");
|
nuclear@2
|
25
|
nuclear@2
|
26 glutDisplayFunc(display);
|
nuclear@2
|
27 glutIdleFunc(idle);
|
nuclear@2
|
28 glutReshapeFunc(reshape);
|
nuclear@2
|
29 glutKeyboardFunc(keyb);
|
nuclear@2
|
30 glutKeyboardUpFunc(keyb_up);
|
nuclear@2
|
31 glutMouseFunc(mouse);
|
nuclear@2
|
32 glutMotionFunc(motion);
|
nuclear@2
|
33 glutSpaceballMotionFunc(sball_motion);
|
nuclear@2
|
34 glutSpaceballRotateFunc(sball_rotate);
|
nuclear@2
|
35
|
nuclear@2
|
36 if(!init()) {
|
nuclear@2
|
37 return 1;
|
nuclear@2
|
38 }
|
nuclear@2
|
39 atexit(cleanup);
|
nuclear@2
|
40
|
nuclear@2
|
41 glutMainLoop();
|
nuclear@2
|
42 return 0;
|
nuclear@2
|
43 }
|
nuclear@2
|
44
|
nuclear@2
|
45 static bool init()
|
nuclear@2
|
46 {
|
nuclear@2
|
47 glewInit();
|
nuclear@2
|
48
|
nuclear@2
|
49 if(!game_init()) {
|
nuclear@2
|
50 return false;
|
nuclear@2
|
51 }
|
nuclear@2
|
52 return true;
|
nuclear@2
|
53 }
|
nuclear@2
|
54
|
nuclear@2
|
55 static void cleanup()
|
nuclear@2
|
56 {
|
nuclear@2
|
57 game_cleanup();
|
nuclear@2
|
58 }
|
nuclear@2
|
59
|
nuclear@2
|
60 static void display()
|
nuclear@2
|
61 {
|
nuclear@2
|
62 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
|
nuclear@2
|
63
|
nuclear@2
|
64 game_update(msec);
|
nuclear@2
|
65 game_render(0);
|
nuclear@2
|
66
|
nuclear@2
|
67 glutSwapBuffers();
|
nuclear@2
|
68 }
|
nuclear@2
|
69
|
nuclear@2
|
70 static void idle()
|
nuclear@2
|
71 {
|
nuclear@2
|
72 glutPostRedisplay();
|
nuclear@2
|
73 }
|
nuclear@2
|
74
|
nuclear@2
|
75 static void reshape(int x, int y)
|
nuclear@2
|
76 {
|
nuclear@2
|
77 game_reshape(x, y);
|
nuclear@2
|
78 }
|
nuclear@2
|
79
|
nuclear@2
|
80 static void keyb(unsigned char key, int x, int y)
|
nuclear@2
|
81 {
|
nuclear@2
|
82 game_keyboard(key, true, x, y);
|
nuclear@2
|
83 }
|
nuclear@2
|
84
|
nuclear@2
|
85 static void keyb_up(unsigned char key, int x, int y)
|
nuclear@2
|
86 {
|
nuclear@2
|
87 game_keyboard(key, false, x, y);
|
nuclear@2
|
88 }
|
nuclear@2
|
89
|
nuclear@2
|
90 static void mouse(int bn, int st, int x, int y)
|
nuclear@2
|
91 {
|
nuclear@2
|
92 game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
|
nuclear@2
|
93 }
|
nuclear@2
|
94
|
nuclear@2
|
95 static void motion(int x, int y)
|
nuclear@2
|
96 {
|
nuclear@2
|
97 game_motion(x, y);
|
nuclear@2
|
98 }
|
nuclear@2
|
99
|
nuclear@2
|
100 #define SBALL_MOVE_SCALE 0.00025
|
nuclear@2
|
101 #define SBALL_ROT_SCALE 0.01
|
nuclear@2
|
102
|
nuclear@2
|
103 static void sball_motion(int x, int y, int z)
|
nuclear@2
|
104 {
|
nuclear@2
|
105 game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
|
nuclear@2
|
106 }
|
nuclear@2
|
107
|
nuclear@2
|
108 static void sball_rotate(int x, int y, int z)
|
nuclear@2
|
109 {
|
nuclear@2
|
110 game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
|
nuclear@2
|
111 }
|