conworlds

view src/vr/vr_libovr.c @ 6:3c36bc28c6c2

more stuff in the vr test
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 21 Aug 2014 01:08:03 +0300
parents 8b7da5ab814e
children bd8202d6d28d
line source
1 #ifdef WIN32
2 #define OVR_OS_WIN32
3 #endif
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "vr_impl.h"
9 #ifdef USE_LIBOVR
10 #include <OVR_CAPI.h>
11 #include <OVR_CAPI_GL.h>
13 static ovrHmd hmd;
15 static int init(void)
16 {
17 int i, num_hmds;
18 union ovrGLConfig glcfg;
20 if(!ovr_Initialize()) {
21 return -1;
22 }
23 printf("initialized LibOVR %s\n", ovr_GetVersionString());
25 if(!(num_hmds = ovrHmd_Detect())) {
26 ovr_Shutdown();
27 return -1;
28 }
29 printf("%d Oculus HMD(s) found\n", num_hmds);
31 hmd = 0;
32 for(i=0; i<num_hmds; i++) {
33 ovrHmd h;
34 if(!(h = ovrHmd_Create(i))) {
35 break;
36 }
37 printf(" [%d]: %s - %s\n", h->Manufacturer, h->ProductName);
39 if(!hmd) {
40 hmd = h;
41 } else {
42 ovrHmd_Destroy(h);
43 }
44 }
46 if(!hmd) {
47 fprintf(stderr, "failed to initialize any Oculus HMDs\n");
48 return -1;
49 }
51 ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0);
53 glcfg.OGL.Header.API = ovrRenderAPI_OpenGL;
54 glcfg.OGL.Header.RTSize = hmd->Resolution;
55 glcfg.OGL.Header.Multisample = 0;
56 glcfg.OGL.Window = 0;
57 glcfg.OGL.DC = 0;
59 if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, eyes_fov, eye_rend_desc))) {
60 fprintf(stderr, "failed to configure LibOVR distortion renderer\n");
61 return -1;
62 }
63 }
65 static void cleanup(void)
66 {
67 if(hmd) {
68 ovrHmd_Destroy(hmd);
69 ovr_Destroy();
70 }
71 }
73 static void view_matrix(int eye, float *mat)
74 {
75 }
77 static void proj_matrix(int eye, float *mat)
78 {
79 }
81 static void begin(int eye)
82 {
83 }
85 static void end(void)
86 {
87 }
89 static void present(void)
90 {
91 }
94 struct vr_module *vr_module_libovr(void)
95 {
96 static struct vr_module m;
98 if(!m.init) {
99 m.name = "libovr";
100 m.init = init;
101 m.cleanup = cleanup;
102 m.view_matrix = view_matrix;
103 m.proj_matrix = proj_matrix;
104 m.begin = begin;
105 m.end = end;
106 m.present = present;
107 }
108 return &m;
109 }
111 #else /* no libovr */
113 static int init(void)
114 {
115 return -1;
116 }
118 struct vr_module *vr_module_libovr(void)
119 {
120 static struct vr_module m;
122 if(!m.init) {
123 m.name = "libovr";
124 m.init = init;
125 }
126 return &m;
127 }
129 #endif /* USE_LIBOVR */