OpenGL ES 2.0 Equivalent for ES 1.0 Circles Using GL_POINT_SMOOTH?

OpenGL ES 2.0 does not have a GL_POINT_SMOOTH definition that ES 1.0 does. This means that the code I used to draw the circles no longer works:

glEnable(GL_POINT_SMOOTH); glPointSize(radius*2); glDrawArrays(GL_POINTS,0,nPoints); 

Is there an equivalent in ES 2.0, maybe something in the vertex shader, or should I use polygons for each circle?

+4
source share
2 answers

You can use point sprites to emulate this. Just turn on dot sprites and you get a special variable gl_PointCoord , which you can read in the fragment shader. This gives you the coordinates of the fragment in the square of the current point. You can simply use them to read a texture containing a circle (the pixels in the circle are not 0) and then discard each fragment whose texture value is 0:

 if(texture2d(circle, gl_PointCoord).r < 0.1) discard; 

EDIT: Or you can do it without texture, due to latency of access to the texture for computational complexity and just estimating the circle equation:

 if(length(gl_PointCoord-vec2(0.5)) > 0.5) discard; 

This can be further optimized by resetting the square root (used in the length function) and comparing with the square radius:

 vec2 pt = gl_PointCoord - vec2(0.5); if(pt.x*pt.x+pt.y*pt.y > 0.25) discard; 

But perhaps the built-in length function is even faster than this, optimized for calculating the length and can be implemented directly in hardware.

+6
source

And the answer is yes, you have to use polygons (like textured quads) to get smooth points.

0
source

Source: https://habr.com/ru/post/1369583/


All Articles