1

I try to get rendered pixels color.

gl.glColor3f(1f, 0, 0);
//draw
gl.glReadPixels(lastX - pw / 2, MyCanvas.this.getHeight()
            - (lastY - ph / 2), pw, ph, GL.GL_RED, GL.GL_FLOAT,
            pixelBuffer);
float r, g, b;
r = pixelBuffer.getFloat();
g = pixelBuffer.getFloat();
b =pixelBuffer.getFloat();
pixelBuffer.rewind();
System.out.println(r+" "+g+" "+b);

there is real pure red color on the screen, but glReadPixels returns to the r very strange value 4.6006E-41, why???

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
michael nesterenko
  • 14,222
  • 25
  • 114
  • 182

2 Answers2

7

glReadPixels documentation says:

Storage parameters set by glPixelStore, such as GL_PACK_LSB_FIRST and GL_PACK_SWAP_BYTES, affect the way that data is written into memory.

So check your glPixelStore configuration. To wit, your byte order is backward.

0x0000803F => 4.600602988224807e-41
0x3F800000 => 1.0

Useful links:

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
0

Use GL_RGB instead of GL_RED as format.

rtn
  • 127,556
  • 20
  • 111
  • 121