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