如何使用抗锯齿在OpenGL中绘制平滑线? [英] How to draw smooth line in OpenGL with antialiasing?

查看:930
本文介绍了如何使用抗锯齿在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆