开发者

Android - How to draw 3D cube on a real scene (no marker, camera is open)

I know I have a basic question, but I can't think how I can draw a cube while the camera is open. I can seperately open the camera or draw a cube in the scene with a background by using GLSurfaceView.Renderer, however, I don't know how to combine these two code :s I mean I don't know how to draw the cube when the camera is open.


I'm still struggling with this problem.. Here how I'm trying to do it:

in the MainActivity, I'm calling the camera view as this:

Preview cameraPreview;
setContentView(R.layout.main);
    cameraPreview =开发者_StackOverflow中文版 new Preview(this);
    ((FrameLayout) findViewById(R.id.preview)).addView(cameraPreview);

and I extend this activity and call the 3D cube to show up on the camera view

However no success,

whenever I include onPause(), onResume() methods in the second one, the application crashes...

Any suggestion ?


This is what called Augmented reality .Take a Framelayout in your xml and add get in in you code by its id . Then add both the SurfaceView and the GlSurfaceView to the FrameLayout.


Other idea:

Steps:
1. Use the SurfaceTexture class to directly upload the camera stream to an OpenGL ES texture
2. Render texture to screen using full-screen textured quad (disable depth buffer writing)
3. draw other stuff on top of camera image using openGL
So what you do: Draw both the camera and the 3d stuff in a GLSurfaceView.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜