vrchess

changeset 9:c2eecf764daa

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Aug 2014 18:48:25 +0300
parents 90abf4b93cc9
children e3f0ca1d008a
files src/game.cc src/main.cc src/vr/vr.c src/vr/vr_libovr.c
diffstat 4 files changed, 31 insertions(+), 17 deletions(-) [+]
line diff
     1.1 --- a/src/game.cc	Fri Aug 22 17:24:43 2014 +0300
     1.2 +++ b/src/game.cc	Fri Aug 22 18:48:25 2014 +0300
     1.3 @@ -22,7 +22,6 @@
     1.4  bool game_init()
     1.5  {
     1.6  	vr_init();
     1.7 -	vr_use_module_named("null");
     1.8  
     1.9  	glEnable(GL_DEPTH_TEST);
    1.10  	glEnable(GL_CULL_FACE);
    1.11 @@ -106,6 +105,8 @@
    1.12  
    1.13  	vr_output_texture(rtarg->get_texture_id(), 0, 0, (float)rtwidth / (float)rtarg->get_width(),
    1.14  		(float)rtheight / (float)rtarg->get_height());
    1.15 +
    1.16 +	vr_swap_buffers();
    1.17  }
    1.18  
    1.19  static void game_render_eye(int eye)
    1.20 @@ -122,11 +123,11 @@
    1.21  	}*/
    1.22  
    1.23  	glMatrixMode(GL_MODELVIEW);
    1.24 -	if(eye == 0 || !vr_view_matrix(eye < 0 ? 0 : 1, mat)) {
    1.25 +	//if(eye == 0 || !vr_view_matrix(eye < 0 ? 0 : 1, mat)) {
    1.26  		glLoadIdentity();
    1.27 -	} else {
    1.28 +	/*} else {
    1.29  		glLoadTransposeMatrixf(mat);
    1.30 -	}
    1.31 +	}*/
    1.32  	glMultTransposeMatrixf(view_matrix[0]);
    1.33  
    1.34  	draw_scene();
    1.35 @@ -160,6 +161,10 @@
    1.36  		switch(key) {
    1.37  		case 27:
    1.38  			exit(0);
    1.39 +
    1.40 +		case ' ':
    1.41 +			vr_recenter();
    1.42 +			break;
    1.43  		}
    1.44  	}
    1.45  
     2.1 --- a/src/main.cc	Fri Aug 22 17:24:43 2014 +0300
     2.2 +++ b/src/main.cc	Fri Aug 22 18:48:25 2014 +0300
     2.3 @@ -70,10 +70,6 @@
     2.4  
     2.5  	game_update(msec);
     2.6  	game_render();
     2.7 -
     2.8 -	if(!vr_swap_buffers()) {
     2.9 -		glutSwapBuffers();
    2.10 -	}
    2.11  }
    2.12  
    2.13  static void idle()
     3.1 --- a/src/vr/vr.c	Fri Aug 22 17:24:43 2014 +0300
     3.2 +++ b/src/vr/vr.c	Fri Aug 22 18:48:25 2014 +0300
     3.3 @@ -71,8 +71,11 @@
     3.4  int vr_use_module(int idx)
     3.5  {
     3.6  	if(idx >= 0 && idx < vr_get_num_active_modules()) {
     3.7 -		vrm = vr_get_active_module(idx);
     3.8 -		printf("using vr module: %s\n", vrm->name);
     3.9 +		struct vr_module *m = vr_get_active_module(idx);
    3.10 +		if(m != vrm) {
    3.11 +			vrm = m;
    3.12 +			printf("using vr module: %s\n", vrm->name);
    3.13 +		}
    3.14  		return 0;
    3.15  	}
    3.16  	return -1;
     4.1 --- a/src/vr/vr_libovr.c	Fri Aug 22 17:24:43 2014 +0300
     4.2 +++ b/src/vr/vr_libovr.c	Fri Aug 22 18:48:25 2014 +0300
     4.3 @@ -86,6 +86,7 @@
     4.4  {
     4.5  	union ovrGLConfig glcfg;
     4.6  	unsigned int dcaps;
     4.7 +	void *win = 0;
     4.8  
     4.9  	deferred_init_done = 1;
    4.10  
    4.11 @@ -93,22 +94,26 @@
    4.12  
    4.13  	glcfg.OGL.Header.API = ovrRenderAPI_OpenGL;
    4.14  	glcfg.OGL.Header.RTSize = hmd->Resolution;
    4.15 -	glcfg.OGL.Header.Multisample = 0;
    4.16 +	glcfg.OGL.Header.Multisample = 1;
    4.17  #ifdef WIN32
    4.18 -	glcfg.OGL.Window = GetActiveWindow();
    4.19 +	win = GetActiveWindow();
    4.20 +	glcfg.OGL.Window = win;
    4.21  	glcfg.OGL.DC = wglGetCurrentDC();
    4.22 -	ovrHmd_AttachToWindow(hmd, glcfg.OGL.Window, 0, 0);
    4.23  	assert(glcfg.OGL.Window);
    4.24 +	assert(glcfg.OGL.DC);
    4.25  #endif
    4.26  
    4.27 -	dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp |
    4.28 -		ovrDistortionCap_Overdrive | ovrDistortionCap_FlipInput;
    4.29 +	ovrHmd_AttachToWindow(hmd, win, 0, 0);
    4.30 +	//ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);
    4.31 +
    4.32 +	dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette;// | ovrDistortionCap_TimeWarp;// |
    4.33 +		//ovrDistortionCap_Overdrive;
    4.34  
    4.35  	if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, dcaps, eye_fov, eye_render_desc)) {
    4.36  		fprintf(stderr, "failed to configure LibOVR distortion renderer\n");
    4.37  	}
    4.38  
    4.39 -	ovrhmd_EnableHSWDisplaySDKRender(hmd, 0);
    4.40 +	//ovrhmd_EnableHSWDisplaySDKRender(hmd, 0);
    4.41  }
    4.42  
    4.43  static void cleanup(void)
    4.44 @@ -207,7 +212,9 @@
    4.45  
    4.46  static int present(void)
    4.47  {
    4.48 -	if(!hmd) return;
    4.49 +	if(!hmd) return 0;
    4.50 +
    4.51 +	glDisable(GL_DEPTH_TEST);
    4.52  
    4.53  	ovrHmd_EndFrame(hmd, pose, &eye_tex[0].Texture);
    4.54  	new_frame = 1;
    4.55 @@ -229,6 +236,9 @@
    4.56  	rect.Size.w = (int)((umax - umin) * texsz.w);
    4.57  	rect.Size.h = (int)((vmax - vmin) * texsz.h);
    4.58  
    4.59 +	printf("eye %d texture: %u [%g, %g] -> [%g, %g]\n", eye, tex, umin, vmin, umax, vmax);
    4.60 +	printf("    pixels [%d, %d] -> [%d, %d]\n", rect.Pos.x, rect.Pos.y, rect.Pos.x + rect.Size.w, rect.Pos.y + rect.Size.h);
    4.61 +
    4.62  	eye_tex[eye].OGL.Header.API = ovrRenderAPI_OpenGL;
    4.63  	eye_tex[eye].OGL.Header.TextureSize = texsz;
    4.64  	eye_tex[eye].OGL.Header.RenderViewport = rect;