如何使用抗锯齿在 OpenGL 中绘制平滑线? [英] How to draw smooth line in OpenGL with antialiasing?
本文介绍了如何使用抗锯齿在 OpenGL 中绘制平滑线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在 OpenGL 中绘制一条平滑的线,这是我所做的:
I need to draw a smooth line in OpenGL and here is what I have done:
glEnable( GL_LINE_SMOOTH );
glEnable( GL_POLYGON_SMOOTH );
glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST );
glBegin( GL_LINE_STRIP );
for( UINT uiPoint = 0; uiPoint < iNumPoints; ++uiPoint )
{
const Coord &Node = vecPoints[uiPoint];
glVertex3f( Node.x, Node.y, Node.z );
}
glEnd();
我还能做什么?
推荐答案
您可以改为生成面向屏幕的细多边形,并根据与线的距离设置片段的 alpha.
You can generate thin, screen-oriented polygons instead, and set the fragment's alpha according to the distance to the line.
示例:
a (0,1) b (0,1)
+--------------------------------------+
A | | B
----+--------------------------------------+----
| |
+--------------------------------------+
d (0,0) c (0,0)
假设您要绘制线段 [AB].
Suppose you want to draw segment [AB].
- 改为绘制多边形 abcd
- 映射 UV((0,0)、(0,1))
- 绑定一个 8x1 的黑白纹理,仅在中心是白色的
- 使用从纹理设置 gl_FragColor.a 的片段着色器进行渲染
(或多或少是 ShaderX5 中使用的技术)
(more or less the technique used in ShaderX5)
但仅当您不能使用 MSAA 时才这样做.
But do this only if you can't use MSAA.
这篇关于如何使用抗锯齿在 OpenGL 中绘制平滑线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文