istereo

diff src/istereo.c @ 21:75a63f9ab7cc

ha!
author John Tsiombikas <nuclear@mutantstargoat.com>
date Wed, 07 Sep 2011 10:49:11 +0300
parents ab4972098eb7
children 889dade25667
line diff
     1.1 --- a/src/istereo.c	Wed Sep 07 10:15:35 2011 +0300
     1.2 +++ b/src/istereo.c	Wed Sep 07 10:49:11 2011 +0300
     1.3 @@ -21,13 +21,16 @@
     1.4  unsigned int prog;
     1.5  unsigned int tex;
     1.6  
     1.7 -int stereo;
     1.8 +int view_xsz, view_ysz;
     1.9 +
    1.10 +int stereo = 1;
    1.11  
    1.12  /* construction parameters */
    1.13  int sides = 24;
    1.14  int segm = 20;
    1.15  float ring_height = 0.5;
    1.16  
    1.17 +float split = 0.5;
    1.18  
    1.19  int init(void)
    1.20  {
    1.21 @@ -44,6 +47,8 @@
    1.22  		return -1;
    1.23  	}
    1.24  
    1.25 +	cam_fov(30.0);
    1.26 +
    1.27  	return 0;
    1.28  }
    1.29  
    1.30 @@ -57,39 +62,47 @@
    1.31  	float pan_x, pan_y, z;
    1.32  	float tsec = get_sec();
    1.33  
    1.34 -	z = ring_height * (segm - 1);
    1.35 +	z = ring_height * segm;
    1.36  	worm(tsec, z, &pan_x, &pan_y);
    1.37  
    1.38 +	glClear(GL_COLOR_BUFFER_BIT);
    1.39 +
    1.40  	if(stereo) {
    1.41 -#if 0
    1.42 +		int split_pt = (int)((float)view_ysz * split);
    1.43 +
    1.44  		/* left eye */
    1.45 -		glDrawBuffer(GL_BACK_LEFT);
    1.46 +		glViewport(0, 0, view_xsz, split_pt);
    1.47 +		cam_aspect((float)split_pt / (float)view_xsz);
    1.48  
    1.49 -		glMatrixMode(GL_PROJECTION);
    1.50 -		glLoadIdentity();
    1.51 +		gl_matrix_mode(GL_PROJECTION);
    1.52 +		gl_load_identity();
    1.53  		cam_stereo_proj_matrix(CAM_LEFT);
    1.54 +		gl_rotatef(-90, 0, 0, 1);
    1.55  
    1.56 -		glMatrixMode(GL_MODELVIEW);
    1.57 -		glLoadIdentity();
    1.58 +		gl_matrix_mode(GL_MODELVIEW);
    1.59 +		gl_load_identity();
    1.60  		cam_stereo_view_matrix(CAM_LEFT);
    1.61 -		glTranslatef(-pan_x, -pan_y, -1.1 * ring_height * segm);
    1.62 +		gl_translatef(-pan_x, -pan_y, -1.1 * ring_height * segm);
    1.63 +		/*gl_rotatef(-90, 0, 0, 1);*/
    1.64  
    1.65  		render(tsec);
    1.66  
    1.67  		/* right eye */
    1.68 -		glDrawBuffer(GL_BACK_RIGHT);
    1.69 +		glViewport(0, split_pt, view_xsz, view_ysz - split_pt);
    1.70 +		cam_aspect((float)(view_ysz - split_pt) / (float)view_xsz);
    1.71  
    1.72 -		glMatrixMode(GL_PROJECTION);
    1.73 -		glLoadIdentity();
    1.74 +		gl_matrix_mode(GL_PROJECTION);
    1.75 +		gl_load_identity();
    1.76  		cam_stereo_proj_matrix(CAM_RIGHT);
    1.77 +		gl_rotatef(-90, 0, 0, 1);
    1.78  
    1.79 -		glMatrixMode(GL_MODELVIEW);
    1.80 -		glLoadIdentity();
    1.81 +		gl_matrix_mode(GL_MODELVIEW);
    1.82 +		gl_load_identity();
    1.83  		cam_stereo_view_matrix(CAM_RIGHT);
    1.84 -		glTranslatef(-pan_x, -pan_y, -1.1 * ring_height * segm);
    1.85 +		gl_translatef(-pan_x, -pan_y, -1.1 * ring_height * segm);
    1.86 +		/*gl_rotatef(-90, 0, 0, 1);*/
    1.87  
    1.88  		render(tsec);
    1.89 -#endif
    1.90  	} else {
    1.91  		gl_matrix_mode(GL_MODELVIEW);
    1.92  		gl_load_identity();
    1.93 @@ -135,8 +148,6 @@
    1.94  
    1.95  static void render(float t)
    1.96  {
    1.97 -	glClear(GL_COLOR_BUFFER_BIT);
    1.98 -
    1.99  	draw_tunnel(t);
   1.100  }
   1.101  
   1.102 @@ -188,6 +199,14 @@
   1.103  	}
   1.104  	gl_end();
   1.105  
   1.106 +	/*gl_begin(GL_QUADS);
   1.107 +	gl_color3f(1.0, 0.3, 0.2);
   1.108 +	gl_vertex2f(-100, -100);
   1.109 +	gl_vertex2f(100, -100);
   1.110 +	gl_vertex2f(100, 0);
   1.111 +	gl_vertex2f(-100, 0);
   1.112 +	gl_end();*/
   1.113 +
   1.114  	bind_texture(0, 0);
   1.115  }
   1.116  
   1.117 @@ -247,7 +266,10 @@
   1.118  
   1.119  	gl_matrix_mode(GL_PROJECTION);
   1.120  	gl_load_identity();
   1.121 -	glu_perspective(45.0, (float)x / (float)y, 1.0, 1000.0);
   1.122 +	glu_perspective(40.0, (float)x / (float)y, 0.5, 500.0);
   1.123 +
   1.124 +	view_xsz = x;
   1.125 +	view_ysz = y;
   1.126  }
   1.127  
   1.128  static unsigned int get_shader_program(const char *vfile, const char *pfile)