I know how to draw round points using fixed pipeline. However I need to do the same using modern OpenGL. Is it possible, or should I use point sprites and textures?
One way would be to draw point sprites with a circle-texture and a self-made alpha test in the fragment shader:
uniform sampler2D circle;
void main()
{
if(texture(circle, gl_PointCoord).r < 0.5)
discard;
...
}
But in fact you don't even need a texture for this, since a circle is a pretty well-defined mathematical concept. So just check the gl_PointCoord
only, which says in which part of the [0,1] square representing the whole point your current fragment is:
vec2 coord = gl_PointCoord - vec2(0.5); //from [0,1] to [-0.5,0.5]
if(length(coord) > 0.5) //outside of circle radius?
discard;