Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL ES glReadPixels returns wrong values
    primarykey
    data
    text
    <p>First of all first time here so hello everyone. After searching the net for days including this site I failed to overcome this problem:</p> <pre><code>public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); //load identity GLU.gluLookAt(gl, 0, -5, -25, 0, 0, 0, 0, 2, 0); //set camera if (fingerInput.isClicking()){ /* Color Picking 4 START */ gl.glDisable(GL10.GL_TEXTURE_2D); //turn off texturing, lighting and fog gl.glDisable(GL10.GL_FOG); gl.glDisable(GL10.GL_LIGHTING); while (i&lt;squares.size()){ //draw picking colors squares.get(i).pickingDraw(gl); //note: picking is the same as draw() only with id colors and not textures i++; } i=0; gl.glReadPixels(fingerInput.getStart().x, screen_height-fingerInput.getStart().y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixels); //read what was the color id pressed, store it in 'pixels' (a 4 slots array buffer) Log.d("tlog","at coords: ("+(screen_height-fingerInput.getStart().x)+", "+(screen_height-fingerInput.getStart().y)+")"); for (j=0; j&lt;4; j++){ RGBA[j] = (int)(pixels.get(j) &amp; 0xff); if (RGBA[j] &lt; 0) RGBA[j]+=256; //correcting error caused by java using unsigned bytes and opengl singed bytes } </code></pre> <p>anyway, for picking purposes, the squares are drawn each with a unique color,(currently drawing 3 squares with colors 99,96 and 93 red, and 0s at blue green alpha) glReadPixels returns on clicking either (99,0,0) or (91,0,0).</p> <p>if the box is colored (x,0,0,255) it returns a value as if it had a list of possible values with spaces of 8 between them. (91,99,107..) sort of "rounding" each read color value to nearest "possible" value.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload