conworlds

diff 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 diff
     1.1 --- a/src/vr/vr_libovr.c	Wed Aug 20 06:33:43 2014 +0300
     1.2 +++ b/src/vr/vr_libovr.c	Wed Aug 20 16:34:43 2014 +0300
     1.3 @@ -1,12 +1,71 @@
     1.4 +#ifdef WIN32
     1.5 +#define OVR_OS_WIN32
     1.6 +#endif
     1.7 +
     1.8 +#include <stdio.h>
     1.9 +#include <stdlib.h>
    1.10 +#include <OVR_CAPI.h>
    1.11 +#include <OVR_CAPI_GL.h>
    1.12  #include "vr_impl.h"
    1.13  
    1.14 +static ovrHmd hmd;
    1.15 +
    1.16  static int init(void)
    1.17  {
    1.18 -	return -1;
    1.19 +	int i, num_hmds;
    1.20 +	union ovrGLConfig glcfg;
    1.21 +
    1.22 +	if(!ovr_Initialize()) {
    1.23 +		return -1;
    1.24 +	}
    1.25 +	printf("initialized LibOVR %s\n", ovr_GetVersionString());
    1.26 +
    1.27 +	if(!(num_hmds = ovrHmd_Detect())) {
    1.28 +		ovr_Shutdown();
    1.29 +		return -1;
    1.30 +	}
    1.31 +	printf("%d Oculus HMD(s) found\n", num_hmds);
    1.32 +
    1.33 +	hmd = 0;
    1.34 +	for(i=0; i<num_hmds; i++) {
    1.35 +		ovrHmd h;
    1.36 +		if(!(h = ovrHmd_Create(i))) {
    1.37 +			break;
    1.38 +		}
    1.39 +		printf(" [%d]: %s - %s\n", h->Manufacturer, h->ProductName);
    1.40 +
    1.41 +		if(!hmd) {
    1.42 +			hmd = h;
    1.43 +		} else {
    1.44 +			ovrHmd_Destroy(h);
    1.45 +		}
    1.46 +	}
    1.47 +
    1.48 +	if(!hmd) {
    1.49 +		fprintf(stderr, "failed to initialize any Oculus HMDs\n");
    1.50 +		return -1;
    1.51 +	}
    1.52 +
    1.53 +	ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0);
    1.54 +
    1.55 +	glcfg.OGL.Header.API = ovrRenderAPI_OpenGL;
    1.56 +	glcfg.OGL.Header.RTSize = hmd->Resolution;
    1.57 +	glcfg.OGL.Header.Multisample = 0;
    1.58 +	glcfg.OGL.Window = 0;
    1.59 +	glcfg.OGL.DC = 0;
    1.60 +
    1.61 +	if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, eyes_fov, eye_rend_desc))) {
    1.62 +		fprintf(stderr, "failed to configure LibOVR distortion renderer\n");
    1.63 +		return -1;
    1.64 +	}
    1.65  }
    1.66  
    1.67  static void cleanup(void)
    1.68  {
    1.69 +	if(hmd) {
    1.70 +		ovrHmd_Destroy(hmd);
    1.71 +		ovr_Destroy();
    1.72 +	}
    1.73  }
    1.74  
    1.75  static void view_matrix(int eye, float *mat)
    1.76 @@ -17,10 +76,19 @@
    1.77  {
    1.78  }
    1.79  
    1.80 -static void draw(unsigned int fbtex, float u, float maxu, float v, float maxv)
    1.81 +static void begin(int eye)
    1.82  {
    1.83  }
    1.84  
    1.85 +static void end(void)
    1.86 +{
    1.87 +}
    1.88 +
    1.89 +static void present(void)
    1.90 +{
    1.91 +}
    1.92 +
    1.93 +
    1.94  struct vr_module *vr_module_libovr(void)
    1.95  {
    1.96  	static struct vr_module m;
    1.97 @@ -31,7 +99,9 @@
    1.98  		m.cleanup = cleanup;
    1.99  		m.view_matrix = view_matrix;
   1.100  		m.proj_matrix = proj_matrix;
   1.101 -		m.draw = draw;
   1.102 +		m.begin = begin;
   1.103 +		m.end = end;
   1.104 +		m.present = present;
   1.105  	}
   1.106  	return &m;
   1.107  }