3dphotoshoot

changeset 7:7f6e6eb3d20e

some progress...
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 23 May 2015 23:14:44 +0300
parents e31e23ead56f
children 9fc7d52f578d
files android/Makefile android/manifest.xml.in src/android/MainActivity.java src/android/camera.c src/camera.h src/game.c
diffstat 6 files changed, 77 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/android/Makefile	Thu May 21 19:03:00 2015 +0300
     1.2 +++ b/android/Makefile	Sat May 23 23:14:44 2015 +0300
     1.3 @@ -79,7 +79,7 @@
     1.4  stop:
     1.5  	adb shell am force-stop $(pkg)
     1.6  
     1.7 -AndroidManifest.xml:
     1.8 +AndroidManifest.xml: manifest.xml.in
     1.9  	android create project -p . -t $(android_platform) -k $(pkg) -a NativeActivity -n $(name)
    1.10  	cat manifest.xml.in | sed 's/$$APPNAME/$(name)/g' | sed 's/$$APPTITLE/$(title)/g' >$@
    1.11  	cd src && rm -f *.java && ln -s ../../src/android/*.java .
     2.1 --- a/android/manifest.xml.in	Thu May 21 19:03:00 2015 +0300
     2.2 +++ b/android/manifest.xml.in	Sat May 23 23:14:44 2015 +0300
     2.3 @@ -12,7 +12,8 @@
     2.4  	<application android:label="$APPNAME" android:debuggable="true">
     2.5  			<!-- android:icon="@drawable/ic_launcher" -->
     2.6  
     2.7 -		<activity android:name="MainActivity" android:label="$APPTITLE">
     2.8 +		<activity android:name="MainActivity" android:label="$APPTITLE"
     2.9 +				android:screenOrientation="landscape">
    2.10  
    2.11  			<meta-data android:name="android.app.lib_name" android:value="$APPNAME"/>
    2.12  
     3.1 --- a/src/android/MainActivity.java	Thu May 21 19:03:00 2015 +0300
     3.2 +++ b/src/android/MainActivity.java	Sat May 23 23:14:44 2015 +0300
     3.3 @@ -6,6 +6,7 @@
     3.4  import android.hardware.Camera;
     3.5  import android.hardware.Camera.CameraInfo;
     3.6  import android.graphics.SurfaceTexture;
     3.7 +
     3.8  /*
     3.9  import android.os.Bundle;
    3.10  import android.content.Context;
    3.11 @@ -22,6 +23,7 @@
    3.12  
    3.13  	// old camera api (fallback)
    3.14  	private static Camera cam;
    3.15 +	private static SurfaceTexture surftex;
    3.16  
    3.17  	public static int start_video(int texid)
    3.18  	{
    3.19 @@ -37,7 +39,7 @@
    3.20  			Log.i(tag, "camera[" + i + "]: " + facing_str);
    3.21  		}
    3.22  
    3.23 -		SurfaceTexture surftex = new SurfaceTexture(texid);
    3.24 +		surftex = new SurfaceTexture(texid);
    3.25  		surftex.setOnFrameAvailableListener(new FrameHandler());
    3.26  
    3.27  		cam = Camera.open();
    3.28 @@ -58,6 +60,14 @@
    3.29  	{
    3.30  		cam.stopPreview();
    3.31  		cam = null;
    3.32 +		surftex = null;
    3.33 +	}
    3.34 +
    3.35 +	public static void update()
    3.36 +	{
    3.37 +		if(cam != null && surftex != null) {
    3.38 +			surftex.updateTexImage();
    3.39 +		}
    3.40  	}
    3.41  }
    3.42  
     4.1 --- a/src/android/camera.c	Thu May 21 19:03:00 2015 +0300
     4.2 +++ b/src/android/camera.c	Sat May 23 23:14:44 2015 +0300
     4.3 @@ -102,6 +102,26 @@
     4.4  	return 0;
     4.5  }
     4.6  
     4.7 +void cam_update(void)
     4.8 +{
     4.9 +	jmethodID method;
    4.10 +
    4.11 +	if(!jvm) {
    4.12 +		fprintf(stderr, "failed to update camera\n");
    4.13 +		return -1;
    4.14 +	}
    4.15 +	if(!cam_is_capturing()) {
    4.16 +		return 0;
    4.17 +	}
    4.18 +
    4.19 +	if(!(method = (*jni)->GetStaticMethodID(jni, activity_class, "update", "()V"))) {
    4.20 +		fprintf(stderr, "failed to find static method: update\n");
    4.21 +		return -1;
    4.22 +	}
    4.23 +	(*jni)->CallStaticVoidMethod(jni, activity_class, method);
    4.24 +	return;
    4.25 +}
    4.26 +
    4.27  int cam_is_capturing(void)
    4.28  {
    4.29  	return capturing;	// XXX is it better to do this properly through JNI?
     5.1 --- a/src/camera.h	Thu May 21 19:03:00 2015 +0300
     5.2 +++ b/src/camera.h	Sat May 23 23:14:44 2015 +0300
     5.3 @@ -19,6 +19,7 @@
     5.4  
     5.5  int cam_start_video(void);
     5.6  int cam_stop_video(void);
     5.7 +void cam_update(void);
     5.8  int cam_is_capturing(void);
     5.9  
    5.10  int cam_take_picture(void);
     6.1 --- a/src/game.c	Thu May 21 19:03:00 2015 +0300
     6.2 +++ b/src/game.c	Sat May 23 23:14:44 2015 +0300
     6.3 @@ -3,6 +3,9 @@
     6.4  #include <math.h>
     6.5  #include "opengl.h"
     6.6  #include "game.h"
     6.7 +#include "camera.h"
     6.8 +
     6.9 +static void draw_quad(float sz);
    6.10  
    6.11  static int win_width, win_height;
    6.12  
    6.13 @@ -11,7 +14,7 @@
    6.14  {
    6.15  	glEnable(GL_DEPTH_TEST);
    6.16  	glEnable(GL_CULL_FACE);
    6.17 -	glEnable(GL_LIGHTING);
    6.18 +	//glEnable(GL_LIGHTING);
    6.19  
    6.20  	glClearColor(0.4, 0.4, 0.4, 1);
    6.21  	return 0;
    6.22 @@ -23,6 +26,9 @@
    6.23  
    6.24  void game_display(unsigned long msec)
    6.25  {
    6.26 +	unsigned int tex = cam_texture();
    6.27 +	//cam_update();
    6.28 +
    6.29  	//float tsec = (float)msec / 1000.0f;
    6.30  
    6.31  	//glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0);
    6.32 @@ -30,6 +36,41 @@
    6.33  
    6.34  	glMatrixMode(GL_MODELVIEW);
    6.35  	glLoadIdentity();
    6.36 +
    6.37 +	if(tex) {
    6.38 +		glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
    6.39 +		glEnable(GL_TEXTURE_EXTERNAL_OES);
    6.40 +
    6.41 +		draw_quad(0.5);
    6.42 +
    6.43 +		glDisable(GL_TEXTURE_EXTERNAL_OES);
    6.44 +	}
    6.45 +}
    6.46 +
    6.47 +static void draw_quad(float sz)
    6.48 +{
    6.49 +	static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1};
    6.50 +	static const float tcarr[] = {0, 0, 1, 0, 1, 1, 0, 1};
    6.51 +	static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    6.52 +
    6.53 +	glPushMatrix();
    6.54 +	glScalef(sz, sz, sz);
    6.55 +
    6.56 +	glEnableClientState(GL_VERTEX_ARRAY);
    6.57 +	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    6.58 +	glEnableClientState(GL_COLOR_ARRAY);
    6.59 +
    6.60 +	glVertexPointer(2, GL_FLOAT, 0, varr);
    6.61 +	glTexCoordPointer(2, GL_FLOAT, 0, tcarr);
    6.62 +	glColorPointer(3, GL_FLOAT, 0, colarr);
    6.63 +
    6.64 +	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    6.65 +
    6.66 +	glDisableClientState(GL_VERTEX_ARRAY);
    6.67 +	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    6.68 +	glDisableClientState(GL_COLOR_ARRAY);
    6.69 +
    6.70 +	glPopMatrix();
    6.71  }
    6.72  
    6.73  void game_reshape(int x, int y)