1

I am able to draw a line in an OpenGL window by specifying the coordinates of 2 vertices, then use glDrawElements to draw a line (GL_LINES) to connect them. However, I want to be able to use the mouse to select the line? What is the best way to do it?

genpfault
  • 51,148
  • 11
  • 85
  • 139
N.T.C
  • 658
  • 2
  • 9
  • 20
  • 1
    One fairly common way to do it is to render the scene but "color" the frame buffer with the object IDs of the scene objects, and then copy that buffer back into RAM and index into it with the X and Y coordinates of the user's mouse when they click to get the ID of the object they clicked on. `picking` would be a good search term to use. – jcarpenter2 Mar 08 '19 at 05:04
  • 1
    Another common option is to perform the intersection tests completely independent of the rendering. Basically, you'll have to intersect the ray through the mouse cursor pixel with the line. – BDL Mar 08 '19 at 08:46
  • see [OpenGL 3D-raypicking with high poly meshes](https://stackoverflow.com/a/51764105/2521214) – Spektre Mar 12 '19 at 12:42

0 Answers0