OpenGL ES 2.0 Equivalent for ES 1.0 Circles Using GL_POINT_SMOOTH?

心不动则不痛 提交于 2019-12-03 13:34:03

问题


OpenGL ES 2.0 doesn't have the GL_POINT_SMOOTH definition which ES 1.0 does. This means code I was using to draw circles no longer works:

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

Is there an equivalent in ES 2.0, perhaps something to go in the vertex shader, or must I use polygons for each circle?


回答1:


You can use point sprites to emulate this. Just enable point sprites and you get a special variable gl_PointCoord that you can read in the fragment shader. This gives you the coordinates of the fragment in the square of the current point. You can just use these to read a texture that contains a circle (pixels not in circle have color of 0) and then discard every fragment, whose texture value is 0:

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

EDIT: Or you can do it without a texture, by trading texture access latency for computational complexity and just evaluating the circle equation:

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

This might be further optimized by dropping the square root (used in the length function) and comparing against the squared radius:

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

But maybe the builtin length function is even faster than this, being optimized for length computation and maybe implemented directly in hardware.




回答2:


And answer is - yes, you must use polygons (e.g. textured quads) to get smooth points.



来源:https://stackoverflow.com/questions/7237086/opengl-es-2-0-equivalent-for-es-1-0-circles-using-gl-point-smooth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!