Android的NDK glReadPixels()的脱屏缓冲区 [英] Android NDK glReadPixels() from offscreen buffer

查看:1941
本文介绍了Android的NDK glReadPixels()的脱屏缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写采用了android NDK游戏。我使用的是采摘选择在OpenGL对象。
对于我有一个屏幕外的帧缓冲区对象,其中i呈现到我用glReadPixels()来从FBO的颜色。颜色则EN codeS点击的对象的ID。

I'm writing a game using android ndk. I'm using picking to select objects in opengl. For that i have an offscreen framebuffer object where i render into and i use glReadPixels() to get the color from the FBO. The color then encodes the id of the clicked object.

问题是glReadPixels()不起作用。它只是无法读取任何颜色值。
有什么我需要做的,使它工作?

The problem is glReadPixels() does not work. It just does not read any color values. Is there anything I have to do, to make it work?

  GLubyte pixel[4] = {0,0,0,0};
  glReadPixels(x, y , 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void *)pixel);

这是我如何尝试使用readpixels。但结果始终是(0,0,0,0)。
我查了一下坐标(X,Y)。他们很好。结合GL_RGBA,GL_UNSIGNED_BYTE也应该被任何OpenGL的支持ES 2.0的实现,根据OpenGL的文档。

This is how i try to use readpixels. But the result is always (0,0,0,0). I checked the coordinates (x,y). They are fine. The combination GL_RGBA, GL_UNSIGNED_BYTE should also be supported by any opengl es 2.0 implementation, according to the opengl docs.

我读过一些关于我在Android清单设置权限。
我试图添加权限是这样的:

I've read something about permissions that I have to set in the android manifest. I tried to add a permission like this:

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

但它也不能工作。

but it didn't work either.

有没有人一个想法是什么解决方案可能是什么?或者我可以看看?

Has anyone an idea what the solution might be? or where I can look at?

推荐答案

这个问题只是一个线程问题。所有的OpenGL调用都在同一个线程来完成。否则,这可能会导致这样更糟怪异behavoir。

the problem was just a threading issue. all openGL calls have to be done in the same thread. Otherwise this can result in weird behavoir like this and worse.

这篇关于Android的NDK glReadPixels()的脱屏缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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