Drawing round points using modern OpenGL

后端 未结 2 1958
囚心锁ツ
囚心锁ツ 2020-12-31 07:10

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?

相关标签:
2条回答
  • 2020-12-31 07:39
    • Drawing circle with shader.
    • OpenGL ES shader sphere.
    0 讨论(0)
  • 2020-12-31 07:50

    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;
    
    0 讨论(0)
提交回复
热议问题