2

So I have this board, to play a boardgame... The problem is, how do I know in which square did the user click on? I know the x and y coordinates, but how do I automate it, without the need to hunt down the specific locations of each square. (Also the size of the board is variable...so it can have lots of squares, or very few, but the board has always the same height and width, that is, the same number of squares running from left to right as the number of squares running from top to bottom).

Thank you so much stack overflow :)

Kos
  • 70,399
  • 25
  • 169
  • 233
dasen
  • 389
  • 2
  • 8
  • 13

2 Answers2

1

There are a lot of options offered at: http://www.opengl.org/resources/faq/technical/selection.htm

Ben Jackson
  • 90,079
  • 9
  • 98
  • 150
  • Could you provide me with an example? – dasen Nov 16 '10 at 22:03
  • This functionality has been deprecated for a really long time and can be not supported on hardware level by today's GPUs; I sincerely recommend to forget about it. – Kos Nov 17 '10 at 11:03
  • 1
    To clarify: The URL in my *answer* has lots of alternative techniques (like rendering a 1x1 color coded viewport) beyond using the builtin GL selection mechanism, which as Kos said is not recommended. – Ben Jackson Nov 17 '10 at 16:48
0

The problem you're talking about is called "picking" and there are several solutions for that:

  • occlusion query-based picking (quite modern, but I haven't tried it yet - there's some rant on that topic here),
  • geometric picking (mathematics, and independent of OpenGL),
  • color-based picking (a bit old and hackish, but very simple to implement).

I have previously described the last approach here:
OpenGL GL_SELECT or manual collision detection?

Community
  • 1
  • 1
Kos
  • 70,399
  • 25
  • 169
  • 233