3dphotoshoot

diff src/game.c @ 9:d1b456d08713

texture matrix and video size from JNI
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 25 May 2015 05:27:26 +0300
parents 9fc7d52f578d
children c71c477521ca
line diff
     1.1 --- a/src/game.c	Mon May 25 04:14:38 2015 +0300
     1.2 +++ b/src/game.c	Mon May 25 05:27:26 2015 +0300
     1.3 @@ -8,6 +8,9 @@
     1.4  static void draw_quad(float hsz, float vsz);
     1.5  
     1.6  static int win_width, win_height;
     1.7 +static float win_aspect;
     1.8 +static int video_width, video_height;
     1.9 +static float video_aspect;
    1.10  
    1.11  
    1.12  int game_init(void)
    1.13 @@ -19,6 +22,14 @@
    1.14  	glClearColor(0.4, 0.4, 0.4, 1);
    1.15  
    1.16  	cam_start_video();
    1.17 +	cam_video_size(&video_width, &video_height);
    1.18 +	if(video_height) {
    1.19 +		video_aspect = (float)video_width / (float)video_height;
    1.20 +	} else {
    1.21 +		video_aspect = 1.0;
    1.22 +	}
    1.23 +
    1.24 +	printf("started video %dx%d (aspect: %g)\n", video_width, video_height, video_aspect);
    1.25  	return 0;
    1.26  }
    1.27  
    1.28 @@ -29,8 +40,13 @@
    1.29  
    1.30  void game_display(unsigned long msec)
    1.31  {
    1.32 -	unsigned int tex = cam_texture();
    1.33 +	unsigned int tex;
    1.34 +	const float *tex_matrix;
    1.35 +	float xscale, yscale;
    1.36 +
    1.37  	cam_update();
    1.38 +	tex = cam_texture();
    1.39 +	tex_matrix = cam_texture_matrix();
    1.40  
    1.41  	//float tsec = (float)msec / 1000.0f;
    1.42  
    1.43 @@ -43,19 +59,34 @@
    1.44  	if(tex) {
    1.45  		glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
    1.46  		glEnable(GL_TEXTURE_EXTERNAL_OES);
    1.47 +
    1.48 +		glMatrixMode(GL_TEXTURE);
    1.49 +		glLoadMatrixf(tex_matrix);
    1.50 +		glMatrixMode(GL_MODELVIEW);
    1.51  	}
    1.52  
    1.53 -	draw_quad(0.5 * 1.33333, 0.5);
    1.54 +	if(video_aspect > win_aspect) {
    1.55 +		xscale = 1.0;
    1.56 +		yscale = 1.0 / video_aspect;
    1.57 +	} else {
    1.58 +		xscale = video_aspect;
    1.59 +		yscale = 1.0;
    1.60 +	}
    1.61 +	draw_quad(xscale, yscale);
    1.62  
    1.63  	if(tex) {
    1.64  		glDisable(GL_TEXTURE_EXTERNAL_OES);
    1.65 +
    1.66 +		glMatrixMode(GL_TEXTURE);
    1.67 +		glLoadIdentity();
    1.68 +		glMatrixMode(GL_MODELVIEW);
    1.69  	}
    1.70  }
    1.71  
    1.72  static void draw_quad(float hsz, float vsz)
    1.73  {
    1.74  	static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1};
    1.75 -	static const float tcarr[] = {0, 1, 1, 1, 1, 0, 0, 0};
    1.76 +	static const float tcarr[] = {0, 0, 1, 0, 1, 1, 0, 1};
    1.77  	static const float colarr[] = {1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1};
    1.78  
    1.79  	glPushMatrix();
    1.80 @@ -82,6 +113,7 @@
    1.81  {
    1.82  	win_width = x;
    1.83  	win_height = y;
    1.84 +	win_aspect = y ? (float)x / (float)y : 1.0;
    1.85  	glViewport(0, 0, x, y);
    1.86  
    1.87  	glMatrixMode(GL_PROJECTION);