oculus1

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main.cc	Fri Aug 30 06:08:34 2013 +0300
     1.3 @@ -0,0 +1,117 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <assert.h>
     1.7 +#include <GL/glew.h>
     1.8 +#ifdef __APPLE__
     1.9 +#include <GLUT/glut.h>
    1.10 +#else
    1.11 +#include <GL/glut.h>
    1.12 +#endif
    1.13 +#include <OVR.h>
    1.14 +#include "camera.h"
    1.15 +
    1.16 +static bool init();
    1.17 +static void cleanup();
    1.18 +static void disp();
    1.19 +static void idle();
    1.20 +static void reshape(int x, int y);
    1.21 +static void keyb(unsigned char key, int x, int y);
    1.22 +static void sball_rotate(int rx, int ry, int rz);
    1.23 +
    1.24 +static Camera cam;
    1.25 +static int width, height;
    1.26 +static OVR::DeviceManager *ovr_devman;
    1.27 +
    1.28 +int main(int argc, char **argv)
    1.29 +{
    1.30 +	glutInit(&argc, argv);
    1.31 +	glutInitWindowSize(1280, 800);
    1.32 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.33 +	glutCreateWindow("oculus test 01");
    1.34 +
    1.35 +	glutDisplayFunc(disp);
    1.36 +	glutIdleFunc(idle);
    1.37 +	glutReshapeFunc(reshape);
    1.38 +	glutKeyboardFunc(keyb);
    1.39 +	glutSpaceballRotateFunc(sball_rotate);
    1.40 +
    1.41 +	glewInit();
    1.42 +
    1.43 +	if(!init()) {
    1.44 +		return 1;
    1.45 +	}
    1.46 +	atexit(cleanup);
    1.47 +
    1.48 +	glutMainLoop();
    1.49 +	return 0;
    1.50 +}
    1.51 +
    1.52 +static bool init()
    1.53 +{
    1.54 +	glEnable(GL_DEPTH_TEST);
    1.55 +	glEnable(GL_LIGHTING);
    1.56 +	glEnable(GL_CULL_FACE);
    1.57 +
    1.58 +	glEnable(GL_LIGHT0);
    1.59 +	glEnable(GL_LIGHTING);
    1.60 +
    1.61 +	// initialize Oculus SDK
    1.62 +	OVR::System::Init();
    1.63 +	if(!(ovr_devman = OVR::DeviceManager::Create())) {
    1.64 +		fprintf(stderr, "failed to create OVR device manager\n");
    1.65 +		return false;
    1.66 +	}
    1.67 +
    1.68 +	return true;
    1.69 +}
    1.70 +
    1.71 +static void cleanup()
    1.72 +{
    1.73 +}
    1.74 +
    1.75 +static void disp()
    1.76 +{
    1.77 +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.78 +
    1.79 +	glMatrixMode(GL_PROJECTION);
    1.80 +	glLoadIdentity();
    1.81 +	gluPerspective(45.0, (float)width / (float)height, 0.5, 500.0);
    1.82 +
    1.83 +	glMatrixMode(GL_MODELVIEW);
    1.84 +	glLoadIdentity();
    1.85 +	glTranslatef(0, 0, -8);
    1.86 +
    1.87 +	float lpos[] = {0, 60, 0, 1};
    1.88 +	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
    1.89 +
    1.90 +	glFrontFace(GL_CW);
    1.91 +	glutSolidTeapot(1.0);
    1.92 +	glFrontFace(GL_CCW);
    1.93 +
    1.94 +	glutSwapBuffers();
    1.95 +	assert(glGetError() == GL_NO_ERROR);
    1.96 +}
    1.97 +
    1.98 +static void idle()
    1.99 +{
   1.100 +	glutPostRedisplay();
   1.101 +}
   1.102 +
   1.103 +
   1.104 +static void reshape(int x, int y)
   1.105 +{
   1.106 +	width = x;
   1.107 +	height = y;
   1.108 +}
   1.109 +
   1.110 +static void keyb(unsigned char key, int x, int y)
   1.111 +{
   1.112 +	switch(key) {
   1.113 +	case 27:
   1.114 +		exit(0);
   1.115 +	}
   1.116 +}
   1.117 +
   1.118 +static void sball_rotate(int rx, int ry, int rz)
   1.119 +{
   1.120 +}