3

I'm working on implementing picking for an OpenGL game I'm writing for android. It's using the "unique color" method of drawing each touchable object as a solid color that is unique to each object. The user input then reads glReadPixels() at the location of the touch. I've gotten the coloring working, and glReadPixels working, but I have been unable to separate the "color" rendering from the main actual rendering, which complicated the use of glReadPixels.

Supposedly the trick to working with this is to render the second scene (for input) into an offscreen buffer, but this seems to be a bit problematic. I've investigated using OpenGL ES1.1 FBO's to act as an offscreen buffer, but it seems my handset (Samsung Galaxy S Vibrant (2.2)) does not support FBO's. I'm at a loss for how to correctly render this scene (and run glReadPixels on it) without the user witnessing it.

Any ideas how offscreen rendering of this sort can be done?

1 Answer 1

4

if FBO is not supported, you can always resort to rendering to your normal back-buffer.

Typical usage would be:

  • Clear back-buffer
  • draw "color-as-id" objects
  • Clear back-buffer
  • draw normal
  • SwapBuffers

The second clear will make sure the picking code will not show up on the final image.

Sign up to request clarification or add additional context in comments.

3 Comments

You'll also need to do a glFlush after drawing the colour-id objects but before reading the colour in the framebuffer
@ryanm: You never need to do a glFlush. glReadPixels will do the flush if it is needed.
The docs don't mention it, but it is entirely reasonable behaviour so you're probably right. Every day's a school day! This strikes me as something that could easily be overlooked in poor-quality OpenGL implementations though...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.