I'm doing a job in openGL. I wanted to click on a window and a drawing appears where it was clicked. Since the 3D eh scenario wanted to know how I can get the coordinate value in Z.
Could someone tell you a step-by-step how to do? =)
I'm doing a job in openGL. I wanted to click on a window and a drawing appears where it was clicked. Since the 3D eh scenario wanted to know how I can get the coordinate value in Z.
Could someone tell you a step-by-step how to do? =)
There are different techniques for working with object selection in OpenGL
. I know these two:
Each object in the scene must have an in-memory id, when you capture the click, you must cycle through all the objects being rendered and check for a collision between the click coordinate and each object. You should apply your projection matrix before checking the collision.
Draw in a separate% color, using different colors for each object, when receiving the click event, read the color of the pixel in that position and see the color in a buffer
dictionary
You have to work on an OpenGL viewport that can be used by OpenGL functions.
So I know 2 solutions:
Use a function that reads a pixel (% with% if I'm not mistaken). But generally this communication between GPU and CPU is slow.
Create a glReadPixel
code that passes the coordinates of the mouse and the texture (created with glsl
) as uniform. The work would be done directly on the GPU, so it would be a more efficient way.