如何使用glreadpixels与Android - 通常得到零 [英] how to use glreadpixels with android -- usually get zeros

查看:325
本文介绍了如何使用glreadpixels与Android - 通常得到零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测光标下的OpenGL的对象......我已阅读 它被称为采摘。这是我的code:

I'm trying to detect the opengl object under the cursor... I have read it referred to as picking. Here is my code:

public int makeBuffer(GL10 gl, int x, int y) {

    ByteBuffer PixelBuffer = ByteBuffer.allocateDirect(4);
    PixelBuffer.order(ByteOrder.nativeOrder());
    PixelBuffer.position(0);
    int mTemp = 0;
    gl.glReadPixels((int)x, (int) y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, PixelBuffer);
    Log.e("Picking", " xy: x" + x + " y"+ y);
    byte b [] = new byte[4];
    PixelBuffer.get(b);
    Log.e("Picking", " rgba: r"+ PixelBuffer.get(0) + " g" + PixelBuffer.get(1) + " b" +
            PixelBuffer.get(2) + " a" + PixelBuffer.get(3));
    Log.e("Picking", " rgba: r"+ b[0] + " g" + b[1] + " b" +
            b[2] + " a" + b[3]);

    //mTemp = PixelBuffer.get(0);
    mTemp = b[0];

    Log.e("Picking", "result:" + mTemp );

    return mTemp;
}

看到大部分的code以上是logcat的语句。我的code打印 零到的画面的r,g,和b。对于阿尔法它打印'-1',这是 翻译到255(无符号)为全alpha。我想检测 彩色屏幕在给定的x / y位置上。我会很乐意用 红色的值是介于1和15之间,因为这是在颜色 应低于触摸。我希望,如果我这样做 完全错了,我会得到所有的零,但是我必须至少做 部分正确的,因为我得到的α。我也包括在线路 我的表现告诉我使用权限的手机 表面护圈和读取帧缓冲区。我不知道是否这些 行工作。

See that most of the code above is logcat statements. My code prints zeros to the screen for r,g, and b. For alpha it prints '-1' which is translatable to 255 (unsigned) as 'full alpha'. I'm trying to detect a color on the screen at the given x/y position. I would be happy with a red value that's somewhere between 1 and 15, as that's the color that should be below the touch. I would expect that if I was doing it entirely wrong I would get all zeroes, but I must be doing it at least partially right, as I'm getting alpha. I have also included lines in my manifest that tell the phone that I use the permissions for the 'surface flinger' and the 'read frame buffer'. I don't know if these lines are working.

<uses-permission
android:name="android.permission.ACCESS_SURFACE_FLINGER" />
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" /

任何帮助将是AP preciated。

any help would be appreciated.

推荐答案

创建Android上的OpenGL ES的应用程序时,我也面临着类似的问题。

I also faced similar issues when creating an openGL ES app on android.

我的解决方法到目前为止是从RGB565改变RGBA8888应用程序。设置渲染器之前插入这些行:

My workaround so far was to change the app from RGB565 to RGBA8888. Insert these lines before setting the renderer:

getHolder().setFormat(PixelFormat.RGBA_8888);
setEGLConfigChooser(8, 8, 8, 8, 0, 0);

您必须意识到,这种解决方案只能在支持RGBA8888设备。

You must be aware that this solution will only work on devices that support RGBA8888.

这篇关于如何使用glreadpixels与Android - 通常得到零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆