libgoatvr

changeset 33:1102327fe85f tip

added red-cyan anaglyph fallback drawing
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 30 Oct 2015 06:34:00 +0200
parents 7eea82cea9d2
children
files src/vr.c src/vr.h
diffstat 2 files changed, 27 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/src/vr.c	Fri Oct 30 06:12:48 2015 +0200
     1.2 +++ b/src/vr.c	Fri Oct 30 06:34:00 2015 +0200
     1.3 @@ -43,16 +43,12 @@
     1.4  		set_option_vec3f(defopt, VR_LEYE_OFFSET, -DEF_IPD * 0.5f, 0.0f, 0.0f);
     1.5  		set_option_vec3f(defopt, VR_REYE_OFFSET, DEF_IPD * 0.5f, 0.0f, 0.0f);
     1.6  
     1.7 -		if((env = getenv("VR_NULL_STEREO_SBS")) && atoi(env)) {
     1.8 -			set_option_int(defopt, VR_NULL_STEREO_SBS, 1);
     1.9 -		} else {
    1.10 -			set_option_int(defopt, VR_NULL_STEREO_SBS, 0);
    1.11 -		}
    1.12 -		if((env = getenv("VR_NULL_STEREO_GL")) && atoi(env)) {
    1.13 -			set_option_int(defopt, VR_NULL_STEREO_GL, 1);
    1.14 -		} else {
    1.15 -			set_option_int(defopt, VR_NULL_STEREO_GL, 0);
    1.16 -		}
    1.17 +		set_option_int(defopt, VR_NULL_STEREO_SBS,
    1.18 +				(env = getenv("VR_NULL_STEREO_SBS")) && atoi(env) ? 1 : 0);
    1.19 +		set_option_int(defopt, VR_NULL_STEREO_GL,
    1.20 +				(env = getenv("VR_NULL_STEREO_GL")) && atoi(env) ? 1 : 0);
    1.21 +		set_option_int(defopt, VR_NULL_STEREO_REDCYAN,
    1.22 +				(env = getenv("VR_NULL_STEREO_REDCYAN")) && atoi(env) ? 1 : 0);
    1.23  	}
    1.24  
    1.25  	if(vrm) {
    1.26 @@ -371,6 +367,7 @@
    1.27  {
    1.28  	int i, show_sbs = vr_geti(VR_NULL_STEREO_SBS);
    1.29  	int use_quadbuf = vr_geti(VR_NULL_STEREO_GL);
    1.30 +	int use_redcyan = vr_geti(VR_NULL_STEREO_REDCYAN);
    1.31  
    1.32  	glPushAttrib(GL_ENABLE_BIT | GL_TRANSFORM_BIT);
    1.33  
    1.34 @@ -379,6 +376,7 @@
    1.35  	glDisable(GL_ALPHA_TEST);
    1.36  	glDisable(GL_STENCIL_TEST);
    1.37  	glDisable(GL_FOG);
    1.38 +	glDisable(GL_BLEND);
    1.39  
    1.40  	glEnable(GL_TEXTURE_2D);
    1.41  
    1.42 @@ -389,10 +387,12 @@
    1.43  	glPushMatrix();
    1.44  	glLoadIdentity();
    1.45  
    1.46 +	glClear(GL_COLOR_BUFFER_BIT);
    1.47 +
    1.48  	for(i=0; i<2; i++) {
    1.49  		float x0, x1;
    1.50  
    1.51 -		if(show_sbs && !use_quadbuf) {
    1.52 +		if(show_sbs && !use_quadbuf && !use_redcyan) {
    1.53  			x0 = i == 0 ? -1 : 0;
    1.54  			x1 = i == 0 ? 0 : 1;
    1.55  		} else {
    1.56 @@ -406,6 +406,17 @@
    1.57  			glDrawBuffer(GL_BACK_LEFT + i);
    1.58  		}
    1.59  
    1.60 +		if(use_redcyan) {
    1.61 +			if(i == 0) {
    1.62 +				glColorMask(1, 0, 0, 1);
    1.63 +			} else {
    1.64 +				glColorMask(0, 1, 1, 1);
    1.65 +
    1.66 +				glEnable(GL_BLEND);
    1.67 +				glBlendFunc(GL_ONE, GL_ONE);
    1.68 +			}
    1.69 +		}
    1.70 +
    1.71  		glBegin(GL_QUADS);
    1.72  		glTexCoord2f(rtarg[i].umin, rtarg[i].vmin);
    1.73  		glVertex2f(x0, -1);
    1.74 @@ -417,12 +428,15 @@
    1.75  		glVertex2f(x0, 1);
    1.76  		glEnd();
    1.77  
    1.78 -		if(!show_sbs && !use_quadbuf) break;
    1.79 +		if(!show_sbs && !use_quadbuf && !use_redcyan) break;
    1.80  	}
    1.81  
    1.82  	if(use_quadbuf) {
    1.83  		glDrawBuffer(GL_BACK);
    1.84  	}
    1.85 +	if(use_redcyan) {
    1.86 +		glColorMask(1, 1, 1, 1);
    1.87 +	}
    1.88  
    1.89  	glPopMatrix();
    1.90  	glMatrixMode(GL_MODELVIEW);
     2.1 --- a/src/vr.h	Fri Oct 30 06:12:48 2015 +0200
     2.2 +++ b/src/vr.h	Fri Oct 30 06:34:00 2015 +0200
     2.3 @@ -21,6 +21,7 @@
     2.4  /* misc options */
     2.5  #define VR_NULL_STEREO_SBS	"null-stereo-sbs"	/* bool, default 0: draw side-by-side */
     2.6  #define VR_NULL_STEREO_GL	"null-stereo-gl"	/* bool, default 0: use quad-buffer stereo */
     2.7 +#define VR_NULL_STEREO_REDCYAN	"null-stereo-redcyan"	/* bool, default 0: draw red-cyan anaglyph stereo */
     2.8  
     2.9  enum {
    2.10  	VR_EYE_LEFT,