3dphotoshoot

diff src/android/camera.c @ 25:ac80210d5fbe

preparing a pc version for easier development of non-android-specifics
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 18 Jun 2015 03:12:30 +0300
parents d1b456d08713
children
line diff
     1.1 --- a/src/android/camera.c	Tue Jun 16 06:17:59 2015 +0300
     1.2 +++ b/src/android/camera.c	Thu Jun 18 03:12:30 2015 +0300
     1.3 @@ -4,6 +4,8 @@
     1.4  #include <jni.h>
     1.5  #include "opengl.h"
     1.6  #include "camera.h"
     1.7 +#include "sdr.h"
     1.8 +#include "sanegl.h"
     1.9  
    1.10  
    1.11  static JavaVM *jvm;
    1.12 @@ -15,6 +17,10 @@
    1.13  static jfloatArray jtex_matrix;
    1.14  static int capturing;
    1.15  
    1.16 +static unsigned int sdr_cam;
    1.17 +static int aloc_vertex, aloc_texcoord;
    1.18 +
    1.19 +
    1.20  int cam_init(void *platform_data)
    1.21  {
    1.22  	int glerr;
    1.23 @@ -26,6 +32,13 @@
    1.24  
    1.25  	jtex_matrix = (*jni)->NewFloatArray(jni, 16);
    1.26  
    1.27 +	// load preview shader
    1.28 +	if(!(sdr_cam = create_program_load("sdr/vertex.glsl", "sdr/android_cam_preview.p.glsl"))) {
    1.29 +		return -1;
    1.30 +	}
    1.31 +	aloc_vertex = glGetAttribLocation(sdr_cam, "attr_vertex");
    1.32 +	aloc_texcoord = glGetAttribLocation(sdr_cam, "attr_texcoord");
    1.33 +
    1.34  	// create the camera texture
    1.35  	assert(glGetError() == GL_NO_ERROR);
    1.36  	glGenTextures(1, &tex);
    1.37 @@ -44,6 +57,8 @@
    1.38  	glDeleteTextures(1, &tex);
    1.39  	tex = 0;
    1.40  
    1.41 +	free_program(sdr_cam);
    1.42 +
    1.43  	if(jni) {
    1.44  		(*jni)->DeleteGlobalRef(jni, jtex_matrix);
    1.45  	}
    1.46 @@ -171,3 +186,28 @@
    1.47  {
    1.48  	return -1;	// TODO
    1.49  }
    1.50 +
    1.51 +void cam_draw_preview(void)
    1.52 +{
    1.53 +	const float *tex_matrix = cam_texture_matrix();
    1.54 +
    1.55 +	gl_matrix_mode(GL_TEXTURE);
    1.56 +	gl_load_matrixf(tex_matrix);
    1.57 +
    1.58 +	glUseProgram(sdr_cam);
    1.59 +	glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
    1.60 +
    1.61 +	gl_begin(GL_QUADS);
    1.62 +	gl_texcoord2f(0, 0);
    1.63 +	gl_vertex2f(-1, -1);
    1.64 +	gl_texcoord2f(1, 0);
    1.65 +	gl_vertex2f(1, -1);
    1.66 +	gl_texcoord2f(1, 1);
    1.67 +	gl_vertex2f(1, 1);
    1.68 +	gl_texcoord2f(0, 1);
    1.69 +	gl_vertex2f(-1, 1);
    1.70 +	gl_end();
    1.71 +
    1.72 +	gl_matrix_mode(GL_TEXTURE);
    1.73 +	gl_load_identity();
    1.74 +}