conworlds

diff src/game.cc @ 4:e6948e131526

adding a vr wrapper
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Aug 2014 06:33:43 +0300
parents a797e426e309
children 3c36bc28c6c2
line diff
     1.1 --- a/src/game.cc	Tue Aug 19 11:01:04 2014 +0300
     1.2 +++ b/src/game.cc	Wed Aug 20 06:33:43 2014 +0300
     1.3 @@ -2,7 +2,7 @@
     1.4  #include "opengl.h"
     1.5  #include "camera.h"
     1.6  #include "texture.h"
     1.7 -//#include "OVR_CAPI_GL.h"
     1.8 +#include "vr/vr.h"
     1.9  
    1.10  static void draw_scene();
    1.11  
    1.12 @@ -15,6 +15,8 @@
    1.13  
    1.14  bool game_init()
    1.15  {
    1.16 +	vr_init();
    1.17 +
    1.18  	glEnable(GL_DEPTH_TEST);
    1.19  	glEnable(GL_CULL_FACE);
    1.20  	glEnable(GL_LIGHTING);
    1.21 @@ -33,6 +35,7 @@
    1.22  void game_cleanup()
    1.23  {
    1.24  	floor_tex.destroy();
    1.25 +	vr_shutdown();
    1.26  }
    1.27  
    1.28  
    1.29 @@ -71,17 +74,26 @@
    1.30  
    1.31  void game_render(int eye)
    1.32  {
    1.33 +	float mat[16];
    1.34  	Matrix4x4 view_matrix = cam.get_matrix().inverse();
    1.35  
    1.36  	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.37  
    1.38  	glMatrixMode(GL_PROJECTION);
    1.39  	glLoadIdentity();
    1.40 -	gluPerspective(60.0, (float)fb_width / (float)fb_height, 0.5, 500.0);
    1.41 +	if(eye == 0 || !vr_proj_matrix(eye < 0 ? 0 : 1, mat)) {
    1.42 +		gluPerspective(60.0, (float)fb_width / (float)fb_height, 0.5, 500.0);
    1.43 +	} else {
    1.44 +		glLoadTransposeMatrixf(mat);
    1.45 +	}
    1.46  
    1.47  	glMatrixMode(GL_MODELVIEW);
    1.48 -	glLoadIdentity();
    1.49 -	glLoadTransposeMatrixf(view_matrix[0]);
    1.50 +	if(eye == 0 || !vr_view_matrix(eye < 0 ? 0 : 1, mat)) {
    1.51 +		glLoadIdentity();
    1.52 +	} else {
    1.53 +		glLoadTransposeMatrixf(mat);
    1.54 +	}
    1.55 +	glMultTransposeMatrixf(view_matrix[0]);
    1.56  
    1.57  	draw_scene();
    1.58  }