c++ - Vizualizing vertex picking of a mesh in OpenGL -
for fun trying build miniature blender using (modern) opengl. part of want user able pick vertices. each time user picks vertex want vertex turn red. question has nothing finding intersecting vertex, rather how 1 visualize picked vertex. have managed paint picked triangle (instead of picked vertex) using following in fragment shader:
if(gl_primitiveid==intersectingface) color=vec4(1.0f,0.0f,0.0f,1.0f);
where intersectingface uniform holds index of meshe's intersecting face.
in order pick vertex instead of face thought of loading sphere mesh scene,scaling down , translating center position of intersecting vertex. wondering whether there simpler solution one.
there built-in variable tells index of vertex, rather the primitive: gl_vertexid.
gl_vertexid: index of vertex being processed.
when using non-indexed rendering, effective index of current vertex (the number of vertices processed + first value). indexed rendering, index used fetch vertex buffer.note: gl_vertexid have base vertex applied it.
so rather setting intersecting face uniform value, doing now, can same vertex index , compare against gl_vertexid
.
Comments
Post a Comment