簡體   English   中英

android中的glReadPixels問題

[英]Problems with glReadPixels in android

我正在嘗試實現我所讀過的opengl選擇系統,並且遇到了glReadPixels的問題。 基本上,場景中的每個節點都具有唯一的顏色,並且當發生新的觸摸時,除了用其唯一的顏色ID繪制的節點外,它僅呈現場景。 我正在嘗試使用存儲的顏色ID列表檢查輸入坐標。

我無法讓glReadPixels正常工作。 對於像素值,它始終返回0 0 0。 我真的很感謝從中獲取正確像素值的任何幫助。 謝謝

這是相關的代碼

private void handleEvent(MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();
    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;
    if (actionCode == 0) {
        // Paint with colorID color
        mSettings.picking(true);
        dumpEvent(event);
        final GL10 gl = mSettings.getGL();

        ByteBuffer PixelBuffer = ByteBuffer.allocateDirect(4);
        PixelBuffer.order(ByteOrder.nativeOrder());
        gl. glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1);
        gl.glReadPixels(x, y, 1, 1, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, PixelBuffer);
        byte b[] = new byte[4];
        PixelBuffer.get(b);
        String key = "" + b[0] + b[1] + b[2];       
        // Check for selection
        mRenderer.processSelection(event, new SGColorI(pixel[0], pixel[1], pixel[2], pixel[3]));

        log.pl("GL on touchdown", key);
    } else if (actionCode == 2) {
        mSettings.picking(false);
    }
}

在這種情況下, allocateDirect “只是行不通”。 使用allocate

這似乎很奇怪,我,但分配VS allocateDirect是我來的唯一區別。

谷歌論壇上的這篇文章也對我有很大幫助。

順便說一句,此發現是在模擬器(幾個不同的版本)而不是實際設備上進行的。

使用glReadPixels解決經典的選擇問題是過分的。 請記住,glReadPixels是一個阻止函數,而openGL主要以異步方式工作。 使用glReadPixels意味着必須處理驅動程序隊列中的所有命令,這可能會浪費大量時間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM