Hi I’m using opengl 3.3 and I think I have figured out a way of knowing what triangle I hower with the mouse trough the fragment shader and some stuff in c++. However for this too work I need to return an integer with only the gl_VertexID of the one fragments vertex whose gl_FragCoord casted to int equals the mouse position while rendering the scene. However I’m not sure how to do that or if it is even possible…
I guess I’ll have to use a framebuffer with a 1D (or 2D) texture, size 1x1, containing GL_INT:s. Which I guess always gets interpolated to that single pixel. Which I then can get out on like color channel 1??
I guess then we will always have an output value for color channel 1 even if we don’t want to set it to anything. So can I get the current value on a specific framebuffer pixel and just use that as output if mouse don’t hower the fragment?
Also another thing that is important is that there is some kind of depth buffer so that the closest fragment is the one which index is returned. Maybe that is sorted out by itself if I render normal with the depth buffer since fragments under won’t be rendered and override the return value to something that Ain’t directly howered?
Also how can I set the value in the 1x1 renderbuffer texture I use in c++ before rendering to like -1 so if that is the value after rendering, nothing was howered?
I really want this to work since it seems like the ultimate way of being able to click stuff.
//Thanks in regards!