conworlds

view src/main.cc @ 4:e6948e131526

adding a vr wrapper
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Aug 2014 06:33:43 +0300
parents 879194e4b1f0
children 3c36bc28c6c2
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "opengl.h"
4 #include "game.h"
6 static bool init();
7 static void cleanup();
9 static void display();
10 static void idle();
11 static void reshape(int x, int y);
12 static void keyb(unsigned char key, int x, int y);
13 static void keyb_up(unsigned char key, int x, int y);
14 static void mouse(int bn, int st, int x, int y);
15 static void motion(int x, int y);
16 static void sball_motion(int x, int y, int z);
17 static void sball_rotate(int x, int y, int z);
19 int main(int argc, char **argv)
20 {
21 glutInitWindowSize(1024, 600);
22 glutInit(&argc, argv);
23 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
24 glutCreateWindow("VR Chess");
26 glutDisplayFunc(display);
27 glutIdleFunc(idle);
28 glutReshapeFunc(reshape);
29 glutKeyboardFunc(keyb);
30 glutKeyboardUpFunc(keyb_up);
31 glutMouseFunc(mouse);
32 glutMotionFunc(motion);
33 glutSpaceballMotionFunc(sball_motion);
34 glutSpaceballRotateFunc(sball_rotate);
36 if(!init()) {
37 return 1;
38 }
39 atexit(cleanup);
41 glutMainLoop();
42 return 0;
43 }
45 static bool init()
46 {
47 glewInit();
49 if(!game_init()) {
50 return false;
51 }
52 return true;
53 }
55 static void cleanup()
56 {
57 game_cleanup();
58 }
60 static void display()
61 {
62 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
64 game_update(msec);
65 game_render(0);
67 glutSwapBuffers();
68 }
70 static void idle()
71 {
72 glutPostRedisplay();
73 }
75 static void reshape(int x, int y)
76 {
77 game_reshape(x, y);
78 }
80 static void keyb(unsigned char key, int x, int y)
81 {
82 game_keyboard(key, true, x, y);
83 }
85 static void keyb_up(unsigned char key, int x, int y)
86 {
87 game_keyboard(key, false, x, y);
88 }
90 static void mouse(int bn, int st, int x, int y)
91 {
92 switch(bn) {
93 case GLUT_RIGHT_BUTTON + 1:
94 if(st == GLUT_DOWN) {
95 game_mwheel(1);
96 }
97 break;
99 case GLUT_RIGHT_BUTTON + 2:
100 if(st == GLUT_DOWN) {
101 game_mwheel(-1);
102 }
103 break;
105 default:
106 game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
107 }
108 }
110 static void motion(int x, int y)
111 {
112 game_motion(x, y);
113 }
115 #define SBALL_MOVE_SCALE 0.00025
116 #define SBALL_ROT_SCALE 0.01
118 static void sball_motion(int x, int y, int z)
119 {
120 game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE);
121 }
123 static void sball_rotate(int x, int y, int z)
124 {
125 game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE);
126 }