I try to implement color picking in Android OpenGL ES.
Here I get the coordinate:
public boolean onTouchEvent(MotionEvent e) {
float x = e.getX();
float y = e.getY();
...
Here I want to get the pixel information on click:
public void processPick(GL10 gl){
ByteBuffer pixel = ByteBuffer.allocate(4);
pixel.order(ByteOrder.nativeOrder());
gl.glReadPixels((int)clickPosX, (int)clickPosY, 1, 1, GL10.GL_RGB, GL10.GL_UNSIGNED_BYTE, pixel);
byte[] b = new byte[3];
pixel.get(b);
Log.d("buffer", b[0] + ", "+b[1]+", "+b[2]);
}
But actually I always get RGB(0, 0, 0), what's wrong? How to set color and pick color correctly?
Anyone can help me? Thanks!
Try this: gl.glReadPixels((int)clickPosX, (int)clickPosY, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixel); byte[] b = new byte[4];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.