selection with transparent textures

Hi,
In My app I render various quads (using various textures) in a 2d plane.
Each texture has an alpha channel, with each pixel of the texture completely opaque or completely transparent.
I’m using this method to display surfaces with irregular edges.
I’m using the selection mode to select the correct visible surface. I need to select only one surface, the one with the pixel under the mouse visible.
OpenGL, in certain cases, doesn’t select one surface (quad), but many.
Where’s the problem?
I need help.
Best regards.

Nicola Mosca

somewhere in time

I think it will output all polys that lie under the cursor that are being drawn. For convex models you’ll get always one probably, and for unconvex you may get multiple.

Originally posted by Michael Steinberg:
I think it will output all polys that lie under the cursor that are being drawn. For convex models you’ll get always one probably, and for unconvex you may get multiple.

Thanks,
Looking at OpenGL State Machine, I discovered
that OpenGL (in selection mode), does not take into account textures & materials.
I have solved my selection problem using stencil buffer.
This is the approach:

  • initialize stencil buffer at some value (0)
  • glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE)
  • for each textured poly
    • glStenciFunc(GL_ALWAYS, index_poly, 0xff)
    • draw poly
  • get mouse position
  • retrieve pixel’s stencil value under the mouse with glReadPixels
  • retrieve poly with the stencil value as index

Results are impressive.
Disadvantages:

  • requires stencil buffer
  • valid stencil values are limited, and are implementation dependent.

Goodbye.

 Nicola Mosca

somewhere in time