title: glReadPixel returns zeros and error 1282 (Android)
body: <p>Here is my picking code</p>
  
  <pre><code>public static void pick(GL11 gl){
          int[] viewport = new int[4];
          ByteBuffer pixel = ByteBuffer.allocateDirect(3).order(ByteOrder.nativeOrder());
  
          mColourR = BaseObject.getColourR();
          mColourG = BaseObject.getColourG();
          mColourB = BaseObject.getColourB();
  
          x = MGLSurfaceView.X();
          y = MGLSurfaceView.Y();
  
          gl.glGetIntegerv(GL11.GL_VIEWPORT,viewport,0);
  
          gl.glReadPixels((int)x, (int)(viewport[3] - y), 1, 1, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, pixel);
          Log.d(TAG, String.valueOf(gl.glGetError()));
          R = pixel.get(0);
          G = pixel.get(1);
          B = pixel.get(2);
          Log.d(TAG, "Colour:" + pixel.get(0) + " " + pixel.get(1) + " " + pixel.get(2));
          if (R == mColourR &amp;&amp; G == mColourG &amp;&amp; B == mColourB){
              match = true;
  
          }else{
              match = false;
          }
          Log.d(TAG, String.valueOf(match));
          Log.d(TAG, String.valueOf(viewport[0]) + "," + String.valueOf(viewport[1]) + "," + String.valueOf(viewport[2]) + "," + String.valueOf(viewport[3]));
  
  } 
  </code></pre>
  
  <p>Sorry about the mess. Anyway this code always seems to return (0,0,0) regardless of where I click. I have a red square, a green, square and a blue background for testing purposes and this method gets called every time one of the squares is drawn and the screen has been pressed like so</p>
  
  <pre><code>BaseObject.newColour();
      mColourR = BaseObject.getColourR();
      mColourG = BaseObject.getColourG();
      mColourB = BaseObject.getColourB();
      gl.glPushMatrix();
      gl.glColor4f(mColourR, mColourG, mColourB, 0.0f);
      gl.glTranslatef(x1, y1, 0);
      square.draw(gl);
      gl.glPopMatrix();
       ColourPicking.pick((GL11)gl);
      match = ColourPicking.getMatch();
      if (match == true){
          x1 = (float) Math.floor(Math.random()*9);
              y1 = (float) Math.floor(Math.random()*7);
          match = false;
      }
  </code></pre>
  
  <p>Even though there is no black space on screen I always get black values so I'm pretty sure its not just a precision problem. I have a log tag in there that returns the viewport values and they're fine, I've also checked my x y coordinates and they seem legit the only thing I have to go on is the 1282 error code.</p>
  
  <p>Does anyone have any idea what this could be?</p>
  
  <p>EDIT: </p>
  
  <p>Right we know that the problem is coming from  the read pixel function because I put glGetError() before and after the function and it came back</p>
  
  <pre><code>Before: 0
  After: 1282
  </code></pre>
  
  <p>Getting rid of scaling didn't help but that was a long shot</p>
  
  <p>I've changed the Buffer to a FloatBuffer and now I'm getting back (0.0, 0.0, 0.0) instead of (0, 0, 0) not much of a victory I know. I also noticed that the error is now 1280 (GL_INVALID_ENUM).  I don't know if this is a step foreward. Does anybody know how to fix this error if not error 1282.</p>