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