conworlds

view src/main.cc @ 6:3c36bc28c6c2

more stuff in the vr test
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 21 Aug 2014 01:08:03 +0300
parents a797e426e309
children bd8202d6d28d
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "opengl.h"
4 #include "game.h"
5 #include "vr/vr.h"
7 static bool init();
8 static void cleanup();
10 static void display();
11 static void idle();
12 static void reshape(int x, int y);
13 static void keyb(unsigned char key, int x, int y);
14 static void keyb_up(unsigned char key, int x, int y);
15 static void mouse(int bn, int st, int x, int y);
16 static void motion(int x, int y);
17 static void sball_motion(int x, int y, int z);
18 static void sball_rotate(int x, int y, int z);
20 int main(int argc, char **argv)
21 {
22 glutInitWindowSize(1024, 600);
23 glutInit(&argc, argv);
24 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
25 glutCreateWindow("VR Chess");
27 glutDisplayFunc(display);
28 glutIdleFunc(idle);
29 glutReshapeFunc(reshape);
30 glutKeyboardFunc(keyb);
31 glutKeyboardUpFunc(keyb_up);
32 glutMouseFunc(mouse);
33 glutMotionFunc(motion);
34 glutSpaceballMotionFunc(sball_motion);
35 glutSpaceballRotateFunc(sball_rotate);
37 if(!init()) {
38 return 1;
39 }
40 atexit(cleanup);
42 glutMainLoop();
43 return 0;
44 }
46 static bool init()
47 {
48 glewInit();
50 if(!game_init()) {
51 return false;
52 }
53 return true;
54 }
56 static void cleanup()
57 {
58 game_cleanup();
59 }
61 static void display()
62 {
63 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
65 game_update(msec);
66 game_render(0);
68 if(!vr_swap_buffers()) {
69 glutSwapBuffers();
70 }
71 }
73 static void idle()
74 {
75 glutPostRedisplay();
76 }
78 static void reshape(int x, int y)
79 {
80 game_reshape(x, y);
81 }
83 static void keyb(unsigned char key, int x, int y)
84 {
85 game_keyboard(key, true, x, y);
86 }
88 static void keyb_up(unsigned char key, int x, int y)
89 {
90 game_keyboard(key, false, x, y);
91 }
93 static void mouse(int bn, int st, int x, int y)
94 {
95 switch(bn) {
96 case GLUT_RIGHT_BUTTON + 1:
97 if(st == GLUT_DOWN) {
98 game_mwheel(1);
99 }
100 break;
102 case GLUT_RIGHT_BUTTON + 2:
103 if(st == GLUT_DOWN) {
104 game_mwheel(-1);
105 }
106 break;
108 default:
109 game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
110 }
111 }
113 static void motion(int x, int y)
114 {
115 game_motion(x, y);
116 }
118 #define SBALL_MOVE_SCALE 0.00025
119 #define SBALL_ROT_SCALE 0.01
121 static void sball_motion(int x, int y, int z)
122 {
123 game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
124 }
126 static void sball_rotate(int x, int y, int z)
127 {
128 game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
129 }