public void initEGL() {
      mEGL =
          (EGL10)
              GLDebugHelper.wrap(
                  EGLContext.getEGL(),
                  GLDebugHelper.CONFIG_CHECK_GL_ERROR | GLDebugHelper.CONFIG_CHECK_THREAD,
                  null);

      mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

      int[] curGLVersion = new int[2];
      mEGL.eglInitialize(mGLDisplay, curGLVersion);

      Log.i("GL", "GL version = " + curGLVersion[0] + "." + curGLVersion[1]);

      EGLConfig[] configs = new EGLConfig[1];
      int[] num_config = new int[1];
      mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1, num_config);
      mGLConfig = configs[0];

      mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv.getHolder(), null);

      mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig, EGL10.EGL_NO_CONTEXT, null);

      mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
      mGL =
          (GL10)
              GLDebugHelper.wrap(
                  mGLContext.getGL(),
                  GLDebugHelper.CONFIG_CHECK_GL_ERROR
                      | GLDebugHelper.CONFIG_CHECK_THREAD
                      | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES,
                  null);
    }
  /* (non-Javadoc)
   * @see android.opengl.GLSurfaceView.Renderer#onDrawFrame(javax.microedition.khronos.opengles.GL10)
   */
  public final void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    if (DEBUG) gl = (GL10) GLDebugHelper.wrap(gl, GLDebugHelper.CONFIG_CHECK_GL_ERROR, log);
    setupDraw2D(gl);
    gl.glDisable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glDisable(GL10.GL_LIGHTING);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureName);
    // load new preview frame as a texture, if needed
    if (frameEnqueued) {
      frameLock.lock();
      if (!isTextureInitialized) {
        initializeTexture(gl);
      } else {
        // just update the image
        // can we just update a portion(non power of two)?...seems to work
        gl.glTexSubImage2D(
            GL10.GL_TEXTURE_2D,
            0,
            0,
            0,
            previewFrameWidth,
            previewFrameHeight,
            mode,
            GL10.GL_UNSIGNED_BYTE,
            frameData);
      }
      frameLock.unlock();
      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
      frameEnqueued = false;
    }

    gl.glColor4f(1, 1, 1, 1f);
    // draw camera preview frame:
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, squareBuffer);

    // draw camera square
    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);

    if (customRenderer != null) customRenderer.setupEnv(gl);
    else {
      gl.glEnable(GL10.GL_LIGHTING);
      gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, ambientLightBuffer);
      gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, diffuseLightBuffer);
      gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, specularLightBuffer);
      gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer);
      gl.glEnable(GL10.GL_LIGHT0);
    }

    markerInfo.draw(gl);

    if (customRenderer != null) customRenderer.draw(gl);

    // take a screenshot, if desired
    if (takeScreenshot) {
      // http://www.anddev.org/how_to_get_opengl_screenshot__useful_programing_hint-t829.html
      takeScreenshot = false;
      int[] tmp = new int[screenHeight * screenWidth];
      int[] screenshot = new int[screenHeight * screenWidth];
      Buffer screenshotBuffer = IntBuffer.wrap(tmp);
      screenshotBuffer.position(0);
      gl.glReadPixels(
          0, 0, screenWidth, screenHeight, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, screenshotBuffer);
      for (int i = 0;
          i < screenHeight;
          i++) { // remember, that OpenGL bitmap is incompatible with Android bitmap
        // and so, some correction need.
        for (int j = 0; j < screenWidth; j++) {
          int pix = tmp[i * screenWidth + j];
          int pb = (pix >> 16) & 0xff;
          int pr = (pix << 16) & 0x00ff0000;
          int pix1 = (pix & 0xff00ff00) | pr | pb;
          screenshot[(screenHeight - i - 1) * screenWidth + j] = pix1;
        }
      }
      this.screenshot = Bitmap.createBitmap(screenshot, screenWidth, screenHeight, Config.RGB_565);

      screenshotTaken = true;
      // wake up the waiting method
      synchronized (screenshotMonitor) {
        screenshotMonitor.notifyAll();
      }
    }
  }