如何在opengl中绘制平滑/消除锯齿的圆圈?

时间:2012-04-28 19:30:09

标签: smooth antialiasing

如何在opengl中绘制平滑/消除锯齿的圆圈?我正在使用glBegin(GL_LINE_LOOP);绘制我的圆圈,但不顺利。 我启用了:

glEnable( GL_LINE_SMOOTH );
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
glEnable(GL_BLEND); 
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

1 个答案:

答案 0 :(得分:0)

This is years late, but the way I did it was using this tutorial.

但是,这仅适用于GL_POINTS

为此,您还需要启用OES_standard_derivatives扩展程序。

顶点:

attribute mediump vec4 Position;
attribute lowp float Size;

void main(void) {
    gl_Position = Position;
    gl_PointSize = Size;
}

片段:

#extension GL_OES_standard_derivatives : enable

void main(void) {
    lowp vec2 cxy = 2.0 * gl_PointCoord - 1.0;
    lowp float radius = dot(cxy, cxy);
    lowp float delta = fwidth(radius);
    lowp float alpha = 1.0 - smoothstep(1.0 - delta, 1.0 + delta, radius);
    gl_FragColor = vec4(1.0, 1.0, 1.0, alpha);
}