My objective is to pick a nearest node(vertex) in a mesh of trias and quads which are huge in number( in a 3D model ).

I am picking by Ray cast method. Now I would like to know that the nearest node is not behind any another triangle or quad.

How to query, whether a particular node is in front of any object in opengl.

Occlusion queries is most certainly what you are looking for.

I have drawn the mesh with glDrawElements.

Can you help me with a sample code, if you have.

I have gone through the manual, but, I could not understand on usage point of view

Help me how to use this.

the vertexshader executes on each vertex of the model, and you want to know which one is nearest to a certain position, maybe “transform feeback” can help. in the vertexshader, you upload this:

```
uniform vec3 position_to_compare = vec3(0, 0, 0);
```

– before you start rendering, upload the “position_to_compare”

– calculate the vertexposition in worldspace

– calculate the distance of that vertex to the “position_to_compare”

– feedback the distance

https://www.khronos.org/opengl/wiki/Transform_Feedback

when done, you have a buffer full of distance values (of all vertices), the next thing would be to figure out what distance is the smallest: a computeshader could do that task, or you could do it yourself on the cpu-side (that would be much slower)

https://www.khronos.org/opengl/wiki/Compute_Shader

[QUOTE=sharath;1286419]I have drawn the mesh with glDrawElements.

Can you help me with a sample code, if you have.

I have gone through the manual, but, I could not understand on usage point of view

Help me how to use this.[/QUOTE]

This might help you. If you still have issues, then post back.

OpenGL is a rendering API, not a modelling or geometry library.

That said, you can use transform-feedback mode or a compute shader as a means to accelerate computations.

Alternatively::if you can accept the limitations, you can render the scene, then project the vertex position to window coordinates, query the relevant pixel from the depth buffer, and test whether the vertex’ depth is greater or less than the value from the depth buffer. This approach may be preferable if you’re going to be rendering the scene anyhow.