Jump to content
  • Advertisement
Sign in to follow this  
MatrixCubed

OpenGL Masked-Pixel Picking Dilemma

This topic is 4591 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, While researching some information for our game engine, a particular problem crossed my mind, which I do not know how to address, or if it's even practical. In our game engine, some objects will be single-quad viewport-aligned-polygon objects (mainly for characters, a la Myth) which can be clicked upon in order to interact with them) whose bitmaps have masked (e.g. alpha test failed) pixels. Since there will be Z ordering of these objects, it would be necessary to know, on a per-pixel basis, which objects are clicked on. However, for example if the mouse were clicked between a character's arm and body (e.g. aimed at the object behind these), without some sort of pixel-perfect hit detection, the character's poly would be returned. OpenGL has selection-buffer rendering which allows you to return the GL name of clicked objects, however if this doesn't take pixel opacity into consideration (and I don't believe it does, but I could be wrong) then it will be useless for my endeavor. Having said that, it sounds like what I must do is something to the effect of, for each viewport-aligned polygon object that intersects a ray cast from the mouse pointer, calculate the location the ray intersects, convert this to 2D coordinates on its respective texture map, check the given pixel's opacity, and if the alpha is greater than 0, return that object's ID; otherwise, continue iteration through the rest of the intersected objects. Ballpark? Wrong league? Wrong sport?

Share this post


Link to post
Share on other sites
Advertisement
Read this thread from this morning. It confirms your thoughts on the selection buffer and gives a good alternative for pixel-perfect selection.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!