Game Development Reference
In-Depth Information
Getting the ARToolKit Running on Android
As mentioned, there are three hurdles to getting the ARToolKit running in Android.
It uses GLUT to control the life cycle of the application, including
creating a window, creating a display surface, providing a main loop,
and processing input events. GLUT is not available in Android.
It uses OpenGL, not OpenGL ES, to draw virtual objects.
It uses Video4Linux to access the hardware camera device at
/dev/video0 . This is possible in rooted devices only.
When I began looking into AR, I thought it would be neat to get the ARTK running on
Android, so I began thinking about ways to overcome these caveats. Guess what?
Somebody already beat me to it. The Project is called AndAR (short for Android Augmented
Reality), 2 and it's an open source project based on the ARToolKit. Here is how the folks of
AndAR overcome the limitations of the PC-based ARTK.
Getting a Video Feed
The PC version of the ARTK for Linux reads the video device directly from /dev/video0 using
the Video4Linux API. Even though Android uses Video4Linux too, the video device is not
accessible by normal applications (they require root access only). This makes it impossible
to read the video feed unless you have a rooted device (which you don't have). To work
around this, AndAR uses the Android Camera API and a surface view.
Using SurfaceView to Display Video
Listing 9-2 shows the CameraSurface class, which used the Android Camera API to render
video on top a surface. Let's take a closer look.
Listing 9-2. Simple Surface View to Display Video
public class CameraSurface extends SurfaceView implements
SurfaceHolder.Callback
{
private static final String TAG = "Preview";
private SurfaceHolder mHolder;
public Camera camera;
2 Android Augmented Reality available online at http://code.google.com/p/andar/ .
 
Search WWH ::




Custom Search