Question about implementing touch events on OpenGL ES

How do I usually handle touch when I create a game with OpenGL?

Once I create a real object to show on the screen,

Create one more object that has the same shape as this.

This fake object has a different color value.

And I’m making a list of color values,

Then, when the touch comes in, draw fake objects and use the glReadPixels function.

The color value of this fake object is read out.

So if the real object matches the color value of the fake object it has, it treats it as touched.

And then I draw the real objects again.

I’ve implemented it this way with what I’ve seen.

It used to work well, but this time the screen flickers because of the fake object drawing.

I don’t think I’m going to use this method, but is there any other way?

I would like a search suggestion.

Use double-buffering and don’t swap buffers while the picking image is in the back buffer. If you’re using a high-level GUI toolkit, it may perform the buffer swap itself, in which case you need to perform the picking as part of the “draw” method, so that you can immediately overwrite the picking image with the “real” image.

Use a framebuffer object (requires 3.0 or later) rather than drawing to the system framebuffer (window).

3.0 also incorporates the EXT_texture_integer extension, so you can potentially use that rather than encoding object IDs as colours.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.