Skip to content Skip to sidebar Skip to footer

Opengl Es 2.0 Android - Color Picking

I'm trying to implement color picking using GLES20.glReadPixels function in android OpenGL ES. The problem is that this function is always returning 0,0,0,0 as color and not the co

Solution 1:

Like all other OpenGL calls, glReadPixels() only works if there is a current OpenGL context.

In Android, OpenGL rendering is mostly done using a GLSurfaceView, which takes care of spawning a secondary thread for rendering, creating an OpenGL context, and making that context current in the secondary rendering thread while invoking the methods in your GLSurfaceView.Renderer implementation.

onTouchEvent() is invoked in the UI thread, so you won't have a current OpenGL context here. To use glReadPixels(), you can forward the request to your rendering thread using the GLSurfaceView.queueEvent() method, and then process it asynchronously the next time your Renderer.onDraw() method is invoked.

Post a Comment for "Opengl Es 2.0 Android - Color Picking"