oculus1

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