title: OpenGL screenshot Android
body: <p>I have an application that uses GLSurfaceView to do some 3-D goodness in Android. I'd like the user to be able to take a screenshot. I think this snippet of code should be storing the pixel colors and storing them inside a bitmap. However, does anyone know how to access the gl10 element that the screen is using, so I can feed it into this function?</p>
  
  <pre><code>public static Bitmap savePixelsOnScreen(int x, int y, int width, int height, GL10 gl){
  int b[]=new int[w*(y+h)];
    int bt[]=new int[w*h];
    IntBuffer ib=IntBuffer.wrap(b);
    ib.position(0);
  //gl.glReadPixels(x, y, w, h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);
  gl.glReadPixels(x, 0, w, y+h, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib);
  
  for(int i=0, k=0; i&lt;h; i++, k++)
  {//remember, that OpenGL bitmap is incompatible with Android bitmap
  //and so, some correction need.        
  for(int j=0; j&lt;w; j++)
  {
  int pix=b[i*w+j];
  int pb=(pix&gt;&gt;16)&amp;0xff;
  int pr=(pix&lt;&lt;16)&amp;0x00ff0000;
  int pix1=(pix&amp;0xff00ff00) | pr | pb;
  bt[(h-k-1)*w+j]=pix1;
  }
  }
  
  
  Bitmap sb=Bitmap.createBitmap(bt, w, h, Bitmap.Config.ARGB_8888);
  return sb;
  return bitmap;
  </code></pre>
  
  <p>I had tried to do this from within the Activity that calls the GLSurfaceView:</p>
  
  <pre><code>EGL10 egl = (EGL10)EGLContext.getEGL(); 
  GL10 gl = (GL10)egl.eglGetCurrentContext().getGL();
  </code></pre>
  
  <p>But every element of the int buffer is zero so I think this is not correct.</p>