oculus1

changeset 0:c7b50cd7184c

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 30 Aug 2013 06:08:34 +0300
parents
children e2f9e4603129
files Makefile src/camera.h src/main.cc
diffstat 3 files changed, 146 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Makefile	Fri Aug 30 06:08:34 2013 +0300
     1.3 @@ -0,0 +1,21 @@
     1.4 +src = $(wildcard src/*.cc)
     1.5 +obj = $(src:.cc=.o)
     1.6 +bin = oculus1
     1.7 +
     1.8 +CXXFLAGS = -pedantic -Wall -g -I/usr/local/include
     1.9 +LDFLAGS = -L/usr/local/lib $(libgl) $(ovrlibs) -lm
    1.10 +
    1.11 +ifeq ($(shell uname -s), Darwin)
    1.12 +	libgl = -framework OpenGL -framework GLUT -lGLEW
    1.13 +	ovrlibs = -lovr -framework CoreFoundation -framework ApplicationServices -framework IOKit
    1.14 +else
    1.15 +	libgl = -lGL -lGLU -lglut -lGLEW
    1.16 +	ovrlibs = -lovr
    1.17 +endif
    1.18 +
    1.19 +$(bin): $(obj)
    1.20 +	$(CXX) -o $@ $(obj) $(LDFLAGS)
    1.21 +
    1.22 +.PHONY: clean
    1.23 +clean:
    1.24 +	rm -f $(obj) $(bin)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/camera.h	Fri Aug 30 06:08:34 2013 +0300
     2.3 @@ -0,0 +1,8 @@
     2.4 +#ifndef CAMERA_H_
     2.5 +#define CAMERA_H_
     2.6 +
     2.7 +class Camera {
     2.8 +public:
     2.9 +};
    2.10 +
    2.11 +#endif	// CAMERA_H_
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/main.cc	Fri Aug 30 06:08:34 2013 +0300
     3.3 @@ -0,0 +1,117 @@
     3.4 +#include <stdio.h>
     3.5 +#include <stdlib.h>
     3.6 +#include <assert.h>
     3.7 +#include <GL/glew.h>
     3.8 +#ifdef __APPLE__
     3.9 +#include <GLUT/glut.h>
    3.10 +#else
    3.11 +#include <GL/glut.h>
    3.12 +#endif
    3.13 +#include <OVR.h>
    3.14 +#include "camera.h"
    3.15 +
    3.16 +static bool init();
    3.17 +static void cleanup();
    3.18 +static void disp();
    3.19 +static void idle();
    3.20 +static void reshape(int x, int y);
    3.21 +static void keyb(unsigned char key, int x, int y);
    3.22 +static void sball_rotate(int rx, int ry, int rz);
    3.23 +
    3.24 +static Camera cam;
    3.25 +static int width, height;
    3.26 +static OVR::DeviceManager *ovr_devman;
    3.27 +
    3.28 +int main(int argc, char **argv)
    3.29 +{
    3.30 +	glutInit(&argc, argv);
    3.31 +	glutInitWindowSize(1280, 800);
    3.32 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    3.33 +	glutCreateWindow("oculus test 01");
    3.34 +
    3.35 +	glutDisplayFunc(disp);
    3.36 +	glutIdleFunc(idle);
    3.37 +	glutReshapeFunc(reshape);
    3.38 +	glutKeyboardFunc(keyb);
    3.39 +	glutSpaceballRotateFunc(sball_rotate);
    3.40 +
    3.41 +	glewInit();
    3.42 +
    3.43 +	if(!init()) {
    3.44 +		return 1;
    3.45 +	}
    3.46 +	atexit(cleanup);
    3.47 +
    3.48 +	glutMainLoop();
    3.49 +	return 0;
    3.50 +}
    3.51 +
    3.52 +static bool init()
    3.53 +{
    3.54 +	glEnable(GL_DEPTH_TEST);
    3.55 +	glEnable(GL_LIGHTING);
    3.56 +	glEnable(GL_CULL_FACE);
    3.57 +
    3.58 +	glEnable(GL_LIGHT0);
    3.59 +	glEnable(GL_LIGHTING);
    3.60 +
    3.61 +	// initialize Oculus SDK
    3.62 +	OVR::System::Init();
    3.63 +	if(!(ovr_devman = OVR::DeviceManager::Create())) {
    3.64 +		fprintf(stderr, "failed to create OVR device manager\n");
    3.65 +		return false;
    3.66 +	}
    3.67 +
    3.68 +	return true;
    3.69 +}
    3.70 +
    3.71 +static void cleanup()
    3.72 +{
    3.73 +}
    3.74 +
    3.75 +static void disp()
    3.76 +{
    3.77 +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    3.78 +
    3.79 +	glMatrixMode(GL_PROJECTION);
    3.80 +	glLoadIdentity();
    3.81 +	gluPerspective(45.0, (float)width / (float)height, 0.5, 500.0);
    3.82 +
    3.83 +	glMatrixMode(GL_MODELVIEW);
    3.84 +	glLoadIdentity();
    3.85 +	glTranslatef(0, 0, -8);
    3.86 +
    3.87 +	float lpos[] = {0, 60, 0, 1};
    3.88 +	glLightfv(GL_LIGHT0, GL_POSITION, lpos);
    3.89 +
    3.90 +	glFrontFace(GL_CW);
    3.91 +	glutSolidTeapot(1.0);
    3.92 +	glFrontFace(GL_CCW);
    3.93 +
    3.94 +	glutSwapBuffers();
    3.95 +	assert(glGetError() == GL_NO_ERROR);
    3.96 +}
    3.97 +
    3.98 +static void idle()
    3.99 +{
   3.100 +	glutPostRedisplay();
   3.101 +}
   3.102 +
   3.103 +
   3.104 +static void reshape(int x, int y)
   3.105 +{
   3.106 +	width = x;
   3.107 +	height = y;
   3.108 +}
   3.109 +
   3.110 +static void keyb(unsigned char key, int x, int y)
   3.111 +{
   3.112 +	switch(key) {
   3.113 +	case 27:
   3.114 +		exit(0);
   3.115 +	}
   3.116 +}
   3.117 +
   3.118 +static void sball_rotate(int rx, int ry, int rz)
   3.119 +{
   3.120 +}