I want to provide the users the functionality that they can choose a polygonal region of an image. One way to implement it is that users can click somewhere of the image and then that point is choosen as a vertex of the polygon. If I do it in that way, I need to connect a window coordinate back to a pixel position. Any function can perform such functionality? Or any better way to implement the polygonal region selection? Thank you.
Some help can be obtained from Ch13 , Red Book on Select and Pick.
Its a kind of feedback mechanism. For exact steps consult it.
No other way in my mind…
depends on what you mean by polygon
If u mean a plain rectangle eg often used in modelling applications to select X number of things
u could then use gluPickMatrix(…)
If instead you mean a more arbitrary polygon, that would require more work
A/ on the CPU construct planes from all the polygons sides + then see if the objects are ‘inside’ the plains
B/ draw the polygon with stencil to X, then afterwards draw each object seeing if the pixels ‘meet?’ the stencil values
Is the objective to use the the mouse to single click and select an object or selecting multiple objects within a region? I’ve read that using the select buffer is outdated but no alternative solutions are offered for region selection. I even tried to implement a select buffer example into some of my code and it crashes when trying to draw objects in select mode so I’m inclined to believe it may be unstable.
gluUnProject might be a good place to start if you are just looking for an easy way to convert window coordinates to model/object coordinates. But that does not offer an easy solution for region selection as you would have to use the mouse points to create a collision region then do all the math yourself to figure out what is colliding with it.