Game Development Reference
In-Depth Information
With CameraSurface in place, the main application activity can then simply add this surface
to its content view, thus rendering the video feed on screen (as shown in this fragment):
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mCameraSurface = new CameraSurface(this);
FrameLayout preview = ((FrameLayout) findViewById(R.id.preview));
preview.addView(mCameraSurface);
}
Hurdles of the Camera Surface and OpenGL
So you now know how to get a video feed to receive preview images that can be used by
the ARTK to render virtual objects on top. However, because you need to render virtual
shapes using OpenGL ES, common sense would suggest that you should start with an
OpenGL (hardware accelerated) surface with a Camera object as a member function; then
when this surface is created, it may initiate a Camera preview along with OpenGL draw
operations overlaid on top. Hence, CameraSurface of Listing 9-2 could be rewritten to allow
for GLES drawing, as shown in Listing 9-3.
Listing 9-3. CameraSurface Version 2
public class CameraSurface extends GLSurfaceView implements
SurfaceHolder.Callback
{
private static final String TAG = "GLPreview";
public Camera camera;
private GLThread mGLThread;
private SurfaceHolder mHolder;
public CameraSurfaceGL(Context context) {
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
}
public void setRenderer(Renderer renderer) {
mGLThread = new GLThread(renderer, getHolder()); // mHolder);
mGLThread.start();
}
 
Search WWH ::




Custom Search