conworlds

view src/vr/vr_libovr.c @ 5:8b7da5ab814e

vr wrapper in progress
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Aug 2014 16:34:43 +0300
parents e6948e131526
children 3c36bc28c6c2
line source
1 #ifdef WIN32
2 #define OVR_OS_WIN32
3 #endif
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <OVR_CAPI.h>
8 #include <OVR_CAPI_GL.h>
9 #include "vr_impl.h"
11 static ovrHmd hmd;
13 static int init(void)
14 {
15 int i, num_hmds;
16 union ovrGLConfig glcfg;
18 if(!ovr_Initialize()) {
19 return -1;
20 }
21 printf("initialized LibOVR %s\n", ovr_GetVersionString());
23 if(!(num_hmds = ovrHmd_Detect())) {
24 ovr_Shutdown();
25 return -1;
26 }
27 printf("%d Oculus HMD(s) found\n", num_hmds);
29 hmd = 0;
30 for(i=0; i<num_hmds; i++) {
31 ovrHmd h;
32 if(!(h = ovrHmd_Create(i))) {
33 break;
34 }
35 printf(" [%d]: %s - %s\n", h->Manufacturer, h->ProductName);
37 if(!hmd) {
38 hmd = h;
39 } else {
40 ovrHmd_Destroy(h);
41 }
42 }
44 if(!hmd) {
45 fprintf(stderr, "failed to initialize any Oculus HMDs\n");
46 return -1;
47 }
49 ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0);
51 glcfg.OGL.Header.API = ovrRenderAPI_OpenGL;
52 glcfg.OGL.Header.RTSize = hmd->Resolution;
53 glcfg.OGL.Header.Multisample = 0;
54 glcfg.OGL.Window = 0;
55 glcfg.OGL.DC = 0;
57 if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, eyes_fov, eye_rend_desc))) {
58 fprintf(stderr, "failed to configure LibOVR distortion renderer\n");
59 return -1;
60 }
61 }
63 static void cleanup(void)
64 {
65 if(hmd) {
66 ovrHmd_Destroy(hmd);
67 ovr_Destroy();
68 }
69 }
71 static void view_matrix(int eye, float *mat)
72 {
73 }
75 static void proj_matrix(int eye, float *mat)
76 {
77 }
79 static void begin(int eye)
80 {
81 }
83 static void end(void)
84 {
85 }
87 static void present(void)
88 {
89 }
92 struct vr_module *vr_module_libovr(void)
93 {
94 static struct vr_module m;
96 if(!m.init) {
97 m.name = "libovr";
98 m.init = init;
99 m.cleanup = cleanup;
100 m.view_matrix = view_matrix;
101 m.proj_matrix = proj_matrix;
102 m.begin = begin;
103 m.end = end;
104 m.present = present;
105 }
106 return &m;
107 }