# HG changeset patch
# User John Tsiombikas <nuclear@member.fsf.org>
# Date 1432412084 -10800
# Node ID 7f6e6eb3d20e12de3e6b81cbd43c643c33f3aaa9
# Parent  e31e23ead56f78813be932794ed4d7c5f9f33223
some progress...

diff -r e31e23ead56f -r 7f6e6eb3d20e android/Makefile
--- a/android/Makefile	Thu May 21 19:03:00 2015 +0300
+++ b/android/Makefile	Sat May 23 23:14:44 2015 +0300
@@ -79,7 +79,7 @@
 stop:
 	adb shell am force-stop $(pkg)
 
-AndroidManifest.xml:
+AndroidManifest.xml: manifest.xml.in
 	android create project -p . -t $(android_platform) -k $(pkg) -a NativeActivity -n $(name)
 	cat manifest.xml.in | sed 's/$$APPNAME/$(name)/g' | sed 's/$$APPTITLE/$(title)/g' >$@
 	cd src && rm -f *.java && ln -s ../../src/android/*.java .
diff -r e31e23ead56f -r 7f6e6eb3d20e android/manifest.xml.in
--- a/android/manifest.xml.in	Thu May 21 19:03:00 2015 +0300
+++ b/android/manifest.xml.in	Sat May 23 23:14:44 2015 +0300
@@ -12,7 +12,8 @@
 	<application android:label="$APPNAME" android:debuggable="true">
 			<!-- android:icon="@drawable/ic_launcher" -->
 
-		<activity android:name="MainActivity" android:label="$APPTITLE">
+		<activity android:name="MainActivity" android:label="$APPTITLE"
+				android:screenOrientation="landscape">
 
 			<meta-data android:name="android.app.lib_name" android:value="$APPNAME"/>
 
diff -r e31e23ead56f -r 7f6e6eb3d20e src/android/MainActivity.java
--- a/src/android/MainActivity.java	Thu May 21 19:03:00 2015 +0300
+++ b/src/android/MainActivity.java	Sat May 23 23:14:44 2015 +0300
@@ -6,6 +6,7 @@
 import android.hardware.Camera;
 import android.hardware.Camera.CameraInfo;
 import android.graphics.SurfaceTexture;
+
 /*
 import android.os.Bundle;
 import android.content.Context;
@@ -22,6 +23,7 @@
 
 	// old camera api (fallback)
 	private static Camera cam;
+	private static SurfaceTexture surftex;
 
 	public static int start_video(int texid)
 	{
@@ -37,7 +39,7 @@
 			Log.i(tag, "camera[" + i + "]: " + facing_str);
 		}
 
-		SurfaceTexture surftex = new SurfaceTexture(texid);
+		surftex = new SurfaceTexture(texid);
 		surftex.setOnFrameAvailableListener(new FrameHandler());
 
 		cam = Camera.open();
@@ -58,6 +60,14 @@
 	{
 		cam.stopPreview();
 		cam = null;
+		surftex = null;
+	}
+
+	public static void update()
+	{
+		if(cam != null && surftex != null) {
+			surftex.updateTexImage();
+		}
 	}
 }
 
diff -r e31e23ead56f -r 7f6e6eb3d20e src/android/camera.c
--- a/src/android/camera.c	Thu May 21 19:03:00 2015 +0300
+++ b/src/android/camera.c	Sat May 23 23:14:44 2015 +0300
@@ -102,6 +102,26 @@
 	return 0;
 }
 
+void cam_update(void)
+{
+	jmethodID method;
+
+	if(!jvm) {
+		fprintf(stderr, "failed to update camera\n");
+		return -1;
+	}
+	if(!cam_is_capturing()) {
+		return 0;
+	}
+
+	if(!(method = (*jni)->GetStaticMethodID(jni, activity_class, "update", "()V"))) {
+		fprintf(stderr, "failed to find static method: update\n");
+		return -1;
+	}
+	(*jni)->CallStaticVoidMethod(jni, activity_class, method);
+	return;
+}
+
 int cam_is_capturing(void)
 {
 	return capturing;	// XXX is it better to do this properly through JNI?
diff -r e31e23ead56f -r 7f6e6eb3d20e src/camera.h
--- a/src/camera.h	Thu May 21 19:03:00 2015 +0300
+++ b/src/camera.h	Sat May 23 23:14:44 2015 +0300
@@ -19,6 +19,7 @@
 
 int cam_start_video(void);
 int cam_stop_video(void);
+void cam_update(void);
 int cam_is_capturing(void);
 
 int cam_take_picture(void);
diff -r e31e23ead56f -r 7f6e6eb3d20e src/game.c
--- a/src/game.c	Thu May 21 19:03:00 2015 +0300
+++ b/src/game.c	Sat May 23 23:14:44 2015 +0300
@@ -3,6 +3,9 @@
 #include <math.h>
 #include "opengl.h"
 #include "game.h"
+#include "camera.h"
+
+static void draw_quad(float sz);
 
 static int win_width, win_height;
 
@@ -11,7 +14,7 @@
 {
 	glEnable(GL_DEPTH_TEST);
 	glEnable(GL_CULL_FACE);
-	glEnable(GL_LIGHTING);
+	//glEnable(GL_LIGHTING);
 
 	glClearColor(0.4, 0.4, 0.4, 1);
 	return 0;
@@ -23,6 +26,9 @@
 
 void game_display(unsigned long msec)
 {
+	unsigned int tex = cam_texture();
+	//cam_update();
+
 	//float tsec = (float)msec / 1000.0f;
 
 	//glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0);
@@ -30,6 +36,41 @@
 
 	glMatrixMode(GL_MODELVIEW);
 	glLoadIdentity();
+
+	if(tex) {
+		glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
+		glEnable(GL_TEXTURE_EXTERNAL_OES);
+
+		draw_quad(0.5);
+
+		glDisable(GL_TEXTURE_EXTERNAL_OES);
+	}
+}
+
+static void draw_quad(float sz)
+{
+	static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1};
+	static const float tcarr[] = {0, 0, 1, 0, 1, 1, 0, 1};
+	static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
+
+	glPushMatrix();
+	glScalef(sz, sz, sz);
+
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+	glEnableClientState(GL_COLOR_ARRAY);
+
+	glVertexPointer(2, GL_FLOAT, 0, varr);
+	glTexCoordPointer(2, GL_FLOAT, 0, tcarr);
+	glColorPointer(3, GL_FLOAT, 0, colarr);
+
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+	glDisableClientState(GL_VERTEX_ARRAY);
+	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+	glDisableClientState(GL_COLOR_ARRAY);
+
+	glPopMatrix();
 }
 
 void game_reshape(int x, int y)