3dphotoshoot
view src/android/MainActivity.java @ 27:3d082c566b53
fixed all the bugs, pc version works
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 18 Jun 2015 04:32:25 +0300 |
parents | d1b456d08713 |
children |
line source
1 package com.mutantstargoat.photoshoot3d;
3 import android.os.Bundle;
4 import android.app.NativeActivity;
5 import android.util.Log;
6 import static android.opengl.GLES20.*;
7 import android.hardware.Camera;
8 import android.hardware.Camera.CameraInfo;
9 import android.graphics.SurfaceTexture;
11 /*
12 import android.content.Context;
13 import android.hardware.camera2.*;
14 */
16 public class MainActivity extends NativeActivity {
17 public static String tag = "photoshoot3d";
18 public static boolean frame_pending;
20 /*
21 static {
22 System.loadLibrary("photoshoot3d");
23 }
24 */
26 @Override
27 protected void onCreate( Bundle savedInstanceState )
28 {
29 super.onCreate( savedInstanceState );
30 }
32 public static void foo()
33 {
34 glClearColor(0.2f, 1.0f, 0.3f, 1.0f);
35 }
37 // old camera api (fallback)
38 private static Camera cam;
39 private static Camera.Parameters params;
40 private static int preview_width, preview_height;
41 private static SurfaceTexture surftex;
43 public static int start_video(int texid)
44 {
45 int num_cams = Camera.getNumberOfCameras();
46 Log.i(tag, "Found " + num_cams + " cameras");
48 if(num_cams < 1) {
49 return -1;
50 }
52 for(int i=0; i<num_cams; i++) {
53 CameraInfo info = new CameraInfo();
54 Camera.getCameraInfo(i, info);
56 String facing_str = info.facing == CameraInfo.CAMERA_FACING_FRONT ? "front" : "back";
58 Log.i(tag, "camera[" + i + "]: " + facing_str);
59 }
61 surftex = new SurfaceTexture(texid);
62 surftex.setOnFrameAvailableListener(new FrameHandler());
64 cam = Camera.open(0);
66 params = cam.getParameters();
67 params.set("orientation", "landscape");
68 cam.setParameters(params);
70 preview_width = params.getPreviewSize().width;
71 preview_height = params.getPreviewSize().height;
73 try {
74 cam.setPreviewTexture(surftex);
75 }
76 catch(java.io.IOException e) {
77 Log.e(tag, "failed to set preview texture");
78 cam = null;
79 return -1;
80 }
81 cam.startPreview();
83 return 0;
84 }
86 public static void stop_video()
87 {
88 cam.stopPreview();
89 cam = null;
90 params = null;
91 surftex = null;
92 }
94 public static synchronized void update(float [] matrix)
95 {
96 if(cam != null && surftex != null) {
97 if(frame_pending) {
98 surftex.updateTexImage();
99 frame_pending = false;
100 }
101 surftex.getTransformMatrix(matrix);
102 }
103 }
104 }
106 class FrameHandler implements SurfaceTexture.OnFrameAvailableListener {
107 @Override
108 public synchronized void onFrameAvailable(SurfaceTexture stex)
109 {
110 MainActivity.frame_pending = true;
111 }
112 }