如何在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);
如何在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);
但是,这仅适用于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);
}