oculus1

view src/main.cc @ 3:b069a5c27388

added a couple more stuff, fixed all the LibOVR line endings
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 15 Sep 2013 04:10:05 +0300
parents e2f9e4603129
children bb81990dc7c8
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <assert.h>
5 #include <GL/glew.h>
6 #ifdef __APPLE__
7 #include <GLUT/glut.h>
8 #else
9 #include <GL/glut.h>
10 #endif
11 #include "vr.h"
12 #include "camera.h"
14 static bool init();
15 static void cleanup();
16 static void disp();
17 static void idle();
18 static void reshape(int x, int y);
19 static void keyb(unsigned char key, int x, int y);
20 static void sball_rotate(int rx, int ry, int rz);
21 static bool parse_args(int argc, char **argv);
23 static Camera cam;
24 static int width, height;
25 static bool use_vr = false;
27 int main(int argc, char **argv)
28 {
29 glutInitWindowSize(1280, 800);
30 glutInit(&argc, argv);
32 if(!parse_args(argc, argv)) {
33 return 1;
34 }
36 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
37 glutCreateWindow("oculus test 01");
39 glutDisplayFunc(disp);
40 glutIdleFunc(idle);
41 glutReshapeFunc(reshape);
42 glutKeyboardFunc(keyb);
43 glutSpaceballRotateFunc(sball_rotate);
45 glewInit();
47 if(!init()) {
48 return 1;
49 }
50 atexit(cleanup);
52 glutMainLoop();
53 return 0;
54 }
56 static bool init()
57 {
58 glEnable(GL_DEPTH_TEST);
59 glEnable(GL_LIGHTING);
60 glEnable(GL_CULL_FACE);
62 glEnable(GL_LIGHT0);
63 glEnable(GL_LIGHTING);
65 if(vr_init(VR_INIT_OCULUS) == -1) {
66 //return false;
67 }
68 return true;
69 }
71 static void cleanup()
72 {
73 vr_shutdown();
74 }
76 static void disp()
77 {
78 // test rift sensor
79 float quat[4], euler[3];
81 vr_get_rotation(quat);
82 vr_get_rotation_euler(euler);
84 printf("q(%.3f + %.3fi + %.3fj %.3fk)", quat[3], quat[0], quat[1], quat[2]);
85 printf(" - euler(%.3f %.3f %.3f)\n", euler[0], euler[1], euler[2]);
87 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
89 glMatrixMode(GL_PROJECTION);
90 glLoadIdentity();
91 gluPerspective(45.0, (float)width / (float)height, 0.5, 500.0);
93 glMatrixMode(GL_MODELVIEW);
94 glLoadIdentity();
95 glTranslatef(0, 0, -8);
97 float lpos[] = {0, 60, 0, 1};
98 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
100 glFrontFace(GL_CW);
101 glutSolidTeapot(1.0);
102 glFrontFace(GL_CCW);
104 glutSwapBuffers();
105 assert(glGetError() == GL_NO_ERROR);
106 }
108 static void idle()
109 {
110 glutPostRedisplay();
111 }
114 static void reshape(int x, int y)
115 {
116 width = x;
117 height = y;
118 }
120 static void keyb(unsigned char key, int x, int y)
121 {
122 switch(key) {
123 case 27:
124 exit(0);
125 }
126 }
128 static void sball_rotate(int rx, int ry, int rz)
129 {
130 }
132 static bool parse_args(int argc, char **argv)
133 {
134 for(int i=1; i<argc; i++) {
135 if(argv[i][0] == '-') {
136 if(strcmp(argv[i], "-vr") == 0) {
137 use_vr = true;
138 } else if(strcmp(argv[i], "-novr") == 0) {
139 use_vr = false;
140 } else {
141 fprintf(stderr, "invalid option: %s\n", argv[i]);
142 return false;
143 }
144 } else {
145 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
146 return false;
147 }
148 }
149 return true;
150 }