oculus1

view src/main.cc @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents c7b50cd7184c
children b069a5c27388
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 glutInit(&argc, argv);
31 if(!parse_args(argc, argv)) {
32 return 1;
33 }
35 glutInitWindowSize(1280, 800);
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 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
80 glMatrixMode(GL_PROJECTION);
81 glLoadIdentity();
82 gluPerspective(45.0, (float)width / (float)height, 0.5, 500.0);
84 glMatrixMode(GL_MODELVIEW);
85 glLoadIdentity();
86 glTranslatef(0, 0, -8);
88 float lpos[] = {0, 60, 0, 1};
89 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
91 glFrontFace(GL_CW);
92 glutSolidTeapot(1.0);
93 glFrontFace(GL_CCW);
95 glutSwapBuffers();
96 assert(glGetError() == GL_NO_ERROR);
97 }
99 static void idle()
100 {
101 glutPostRedisplay();
102 }
105 static void reshape(int x, int y)
106 {
107 width = x;
108 height = y;
109 }
111 static void keyb(unsigned char key, int x, int y)
112 {
113 switch(key) {
114 case 27:
115 exit(0);
116 }
117 }
119 static void sball_rotate(int rx, int ry, int rz)
120 {
121 }
123 static bool parse_args(int argc, char **argv)
124 {
125 for(int i=1; i<argc; i++) {
126 if(argv[i][0] == '-') {
127 if(strcmp(argv[i], "-vr") == 0) {
128 use_vr = true;
129 } else if(strcmp(argv[i], "-novr") == 0) {
130 use_vr = false;
131 } else {
132 fprintf(stderr, "invalid option: %s\n", argv[i]);
133 return false;
134 }
135 } else {
136 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
137 return false;
138 }
139 }
140 return true;
141 }