glReadPixel在android 1.6中返回0

时间:2010-11-02 04:52:47

标签: android opengl-es

我使用min3d将* .obj格式的3D模型导入到Android 1.6。但是,我需要检测出我正在触摸的那张脸。所以我打算使用以下代码使用颜色选择。

FloatBuffer pixel = FloatBuffer.allocate(4);
                IntBuffer viewport = IntBuffer.allocate(4);
                gl.glGetIntegerv(GL11.GL_VIEWPORT, viewport);
                gl.glFlush();
                viewport.position(0);
                gl.glReadPixels((int) x, (int) (viewport.get(3) - y), 1, 1,
                        GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, pixel);

                Log.d("Pixel Values:", pixel.get(0) + " " + pixel.get(1) + " "
                        + pixel.get(2) + " " + pixel.get(3));

其中x和y是从onTouch侦听器接收的坐标。执行此代码时,我总是在日志中得到0 0 0 0。怎么解决这个问题?

1 个答案:

答案 0 :(得分:0)

我不是Android的用户,但你将FloatBuffer传递给glReadPixels并输入GL_UNSIGNED_BYTE,也许你想要一个ByteBuffer或切换类型为GL_FLOAT。