3dphotoshoot
changeset 8:9fc7d52f578d
FINALLY I'm getting an image out of the camera
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 25 May 2015 04:14:38 +0300 |
parents | 7f6e6eb3d20e |
children | d1b456d08713 |
files | src/android/MainActivity.java src/android/amain.c src/android/camera.c src/camera.h src/game.c |
diffstat | 5 files changed, 34 insertions(+), 23 deletions(-) [+] |
line diff
1.1 --- a/src/android/MainActivity.java Sat May 23 23:14:44 2015 +0300 1.2 +++ b/src/android/MainActivity.java Mon May 25 04:14:38 2015 +0300 1.3 @@ -15,6 +15,7 @@ 1.4 1.5 public class MainActivity extends NativeActivity { 1.6 public static String tag = "photoshoot3d"; 1.7 + public static boolean frame_pending; 1.8 1.9 public static void foo() 1.10 { 1.11 @@ -30,6 +31,10 @@ 1.12 int num_cams = Camera.getNumberOfCameras(); 1.13 Log.i(tag, "Found " + num_cams + " cameras"); 1.14 1.15 + if(num_cams < 1) { 1.16 + return -1; 1.17 + } 1.18 + 1.19 for(int i=0; i<num_cams; i++) { 1.20 CameraInfo info = new CameraInfo(); 1.21 Camera.getCameraInfo(i, info); 1.22 @@ -42,7 +47,12 @@ 1.23 surftex = new SurfaceTexture(texid); 1.24 surftex.setOnFrameAvailableListener(new FrameHandler()); 1.25 1.26 - cam = Camera.open(); 1.27 + cam = Camera.open(0); 1.28 + 1.29 + Camera.Parameters params = cam.getParameters(); 1.30 + params.set("orientation", "landscape"); 1.31 + cam.setParameters(params); 1.32 + 1.33 try { 1.34 cam.setPreviewTexture(surftex); 1.35 } 1.36 @@ -63,10 +73,11 @@ 1.37 surftex = null; 1.38 } 1.39 1.40 - public static void update() 1.41 + public static synchronized void update() 1.42 { 1.43 - if(cam != null && surftex != null) { 1.44 + if(cam != null && surftex != null && frame_pending) { 1.45 surftex.updateTexImage(); 1.46 + frame_pending = false; 1.47 } 1.48 } 1.49 } 1.50 @@ -75,7 +86,6 @@ 1.51 @Override 1.52 public synchronized void onFrameAvailable(SurfaceTexture stex) 1.53 { 1.54 - Log.i(MainActivity.tag, "new video frame"); 1.55 - stex.updateTexImage(); 1.56 + MainActivity.frame_pending = true; 1.57 } 1.58 }
2.1 --- a/src/android/amain.c Sat May 23 23:14:44 2015 +0300 2.2 +++ b/src/android/amain.c Mon May 25 04:14:38 2015 +0300 2.3 @@ -28,8 +28,6 @@ 2.4 static JNIEnv *jni; 2.5 static jclass activity_class; 2.6 2.7 -static unsigned int camtex; 2.8 - 2.9 2.10 2.11 void android_main(struct android_app *app_ptr) 2.12 @@ -100,7 +98,6 @@ 2.13 if(cam_init(&cam_data) == -1) { 2.14 exit(1); 2.15 } 2.16 - cam_start_video(); 2.17 2.18 /* initialize the application */ 2.19 if(game_init() == -1) { 2.20 @@ -113,18 +110,17 @@ 2.21 /* cleanup */ 2.22 init_done = 0; 2.23 game_shutdown(); 2.24 - cam_shutdown(); 2.25 destroy_gl(); 2.26 break; 2.27 2.28 case APP_CMD_GAINED_FOCUS: 2.29 /* app focused */ 2.30 - cam_start_video(); 2.31 + //cam_start_video(); 2.32 break; 2.33 2.34 case APP_CMD_LOST_FOCUS: 2.35 /* app lost focus */ 2.36 - cam_stop_video(); 2.37 + //cam_stop_video(); 2.38 break; 2.39 2.40 case APP_CMD_WINDOW_RESIZED:
3.1 --- a/src/android/camera.c Sat May 23 23:14:44 2015 +0300 3.2 +++ b/src/android/camera.c Mon May 25 04:14:38 2015 +0300 3.3 @@ -102,7 +102,7 @@ 3.4 return 0; 3.5 } 3.6 3.7 -void cam_update(void) 3.8 +int cam_update(void) 3.9 { 3.10 jmethodID method; 3.11 3.12 @@ -119,7 +119,7 @@ 3.13 return -1; 3.14 } 3.15 (*jni)->CallStaticVoidMethod(jni, activity_class, method); 3.16 - return; 3.17 + return 0; 3.18 } 3.19 3.20 int cam_is_capturing(void)
4.1 --- a/src/camera.h Sat May 23 23:14:44 2015 +0300 4.2 +++ b/src/camera.h Mon May 25 04:14:38 2015 +0300 4.3 @@ -19,7 +19,7 @@ 4.4 4.5 int cam_start_video(void); 4.6 int cam_stop_video(void); 4.7 -void cam_update(void); 4.8 +int cam_update(void); 4.9 int cam_is_capturing(void); 4.10 4.11 int cam_take_picture(void);
5.1 --- a/src/game.c Sat May 23 23:14:44 2015 +0300 5.2 +++ b/src/game.c Mon May 25 04:14:38 2015 +0300 5.3 @@ -5,7 +5,7 @@ 5.4 #include "game.h" 5.5 #include "camera.h" 5.6 5.7 -static void draw_quad(float sz); 5.8 +static void draw_quad(float hsz, float vsz); 5.9 5.10 static int win_width, win_height; 5.11 5.12 @@ -17,17 +17,20 @@ 5.13 //glEnable(GL_LIGHTING); 5.14 5.15 glClearColor(0.4, 0.4, 0.4, 1); 5.16 + 5.17 + cam_start_video(); 5.18 return 0; 5.19 } 5.20 5.21 void game_shutdown(void) 5.22 { 5.23 + cam_shutdown(); 5.24 } 5.25 5.26 void game_display(unsigned long msec) 5.27 { 5.28 unsigned int tex = cam_texture(); 5.29 - //cam_update(); 5.30 + cam_update(); 5.31 5.32 //float tsec = (float)msec / 1000.0f; 5.33 5.34 @@ -40,21 +43,23 @@ 5.35 if(tex) { 5.36 glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex); 5.37 glEnable(GL_TEXTURE_EXTERNAL_OES); 5.38 + } 5.39 5.40 - draw_quad(0.5); 5.41 + draw_quad(0.5 * 1.33333, 0.5); 5.42 5.43 + if(tex) { 5.44 glDisable(GL_TEXTURE_EXTERNAL_OES); 5.45 } 5.46 } 5.47 5.48 -static void draw_quad(float sz) 5.49 +static void draw_quad(float hsz, float vsz) 5.50 { 5.51 static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1}; 5.52 - static const float tcarr[] = {0, 0, 1, 0, 1, 1, 0, 1}; 5.53 - static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 5.54 + static const float tcarr[] = {0, 1, 1, 1, 1, 0, 0, 0}; 5.55 + static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 5.56 5.57 glPushMatrix(); 5.58 - glScalef(sz, sz, sz); 5.59 + glScalef(hsz, vsz, 1); 5.60 5.61 glEnableClientState(GL_VERTEX_ARRAY); 5.62 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 5.63 @@ -62,9 +67,9 @@ 5.64 5.65 glVertexPointer(2, GL_FLOAT, 0, varr); 5.66 glTexCoordPointer(2, GL_FLOAT, 0, tcarr); 5.67 - glColorPointer(3, GL_FLOAT, 0, colarr); 5.68 + glColorPointer(4, GL_FLOAT, 0, colarr); 5.69 5.70 - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 5.71 + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 5.72 5.73 glDisableClientState(GL_VERTEX_ARRAY); 5.74 glDisableClientState(GL_TEXTURE_COORD_ARRAY);