title: How to render Android's YUV-NV21 camera image on the background in libgdx with OpenGLES 2.0 in real-time?
body: <p>Unlike Android, I'm relatively new to GL/libgdx. The task I need to solve, namely rendering the Android camera's YUV-NV21 preview image to the screen background inside libgdx in real time is multi-faceted. Here are the main concerns:</p>
  
  <ol>
  <li><p>Android camera's preview image is only guaranteed to be in the YUV-NV21 space (and in the similar YV12 space where U and V channels are not interleaved but grouped). Assuming that most modern devices will provide implicit RGB conversion is VERY wrong, e.g the newest Samsung Note 10.1 2014 version only provides the YUV formats. Since nothing can be drawn to the screen in OpenGL unless it is in RGB, the color space must somehow be converted. </p></li>
  <li><p>The example in the libgdx documentation (<a href="https://github.com/libgdx/libgdx/wiki/Integrating-libgdx-and-the-device-camera" rel="noreferrer">Integrating libgdx and the device camera</a>) uses an Android surface view that is below everything to draw the image on with GLES 1.1. Since the beginning of March 2014, OpenGLES 1.x support is removed from libgdx due to being obsolete and nearly all devices now supporting GLES 2.0. If you try the same sample with GLES 2.0, the 3D objects you draw on the image will be half-transparent. Since the surface behind has nothing to do with GL, this cannot really be controlled. Disabling BLENDING/TRANSLUCENCY does not work. Therefore, rendering this image must be done purely in GL. </p></li>
  <li><p>This has to be done in real-time, so the color space conversion must be VERY fast. Software conversion using Android bitmaps will probably be too slow. </p></li>
  <li><p>As a side-feature, the camera image must be accessible from the Android code in order to perform other tasks than drawing it on the screen, e.g sending it to a native image processor through JNI. </p></li>
  </ol>
  
  <p>The question is, how is this task done properly and as fast as possible?</p>