oculus1
view src/main.cc @ 0:c7b50cd7184c
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 30 Aug 2013 06:08:34 +0300 |
parents | |
children | e2f9e4603129 |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <assert.h>
4 #include <GL/glew.h>
5 #ifdef __APPLE__
6 #include <GLUT/glut.h>
7 #else
8 #include <GL/glut.h>
9 #endif
10 #include <OVR.h>
11 #include "camera.h"
13 static bool init();
14 static void cleanup();
15 static void disp();
16 static void idle();
17 static void reshape(int x, int y);
18 static void keyb(unsigned char key, int x, int y);
19 static void sball_rotate(int rx, int ry, int rz);
21 static Camera cam;
22 static int width, height;
23 static OVR::DeviceManager *ovr_devman;
25 int main(int argc, char **argv)
26 {
27 glutInit(&argc, argv);
28 glutInitWindowSize(1280, 800);
29 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
30 glutCreateWindow("oculus test 01");
32 glutDisplayFunc(disp);
33 glutIdleFunc(idle);
34 glutReshapeFunc(reshape);
35 glutKeyboardFunc(keyb);
36 glutSpaceballRotateFunc(sball_rotate);
38 glewInit();
40 if(!init()) {
41 return 1;
42 }
43 atexit(cleanup);
45 glutMainLoop();
46 return 0;
47 }
49 static bool init()
50 {
51 glEnable(GL_DEPTH_TEST);
52 glEnable(GL_LIGHTING);
53 glEnable(GL_CULL_FACE);
55 glEnable(GL_LIGHT0);
56 glEnable(GL_LIGHTING);
58 // initialize Oculus SDK
59 OVR::System::Init();
60 if(!(ovr_devman = OVR::DeviceManager::Create())) {
61 fprintf(stderr, "failed to create OVR device manager\n");
62 return false;
63 }
65 return true;
66 }
68 static void cleanup()
69 {
70 }
72 static void disp()
73 {
74 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
76 glMatrixMode(GL_PROJECTION);
77 glLoadIdentity();
78 gluPerspective(45.0, (float)width / (float)height, 0.5, 500.0);
80 glMatrixMode(GL_MODELVIEW);
81 glLoadIdentity();
82 glTranslatef(0, 0, -8);
84 float lpos[] = {0, 60, 0, 1};
85 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
87 glFrontFace(GL_CW);
88 glutSolidTeapot(1.0);
89 glFrontFace(GL_CCW);
91 glutSwapBuffers();
92 assert(glGetError() == GL_NO_ERROR);
93 }
95 static void idle()
96 {
97 glutPostRedisplay();
98 }
101 static void reshape(int x, int y)
102 {
103 width = x;
104 height = y;
105 }
107 static void keyb(unsigned char key, int x, int y)
108 {
109 switch(key) {
110 case 27:
111 exit(0);
112 }
113 }
115 static void sball_rotate(int rx, int ry, int rz)
116 {
117 }