逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::
Antialiasing 
Another use for OpenGL’s blending capabilities is antialiasing. 
Turning on antialiasing is simple. 
First: you must enable blending and set the blending function.
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Second: choose to antialias points, lines, and/or polygons(any solid primitive) by  calling glEnable:
glEnable(GL_POINT_SMOOTH);  // Smooth out points.(smooth out: 使平滑)
glEnable(GL_LINE_SMOOTH); // Smooth out lines.
glEnable(GL_POLYGON_SMOOTH); // Smooth out polygon edges.

Third: give hint to do the best job possible:
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);


Solid objects antialiasing called "multisampling", more tedious rules.

Point and line smoothing is widely supported, but unfortunately polygon smoothing is not available on all platforms. Even when GL_POLYGON_SMOOTH is available, it is not as convenient a means of having your whole scene antialiased as you might think. Because it is based on the blending operation, you would need to sort all your primitives from front to back! Yuck.


Multisample(抽样):
A more recent addition to OpenGL to address this shortcoming is multisampling. When this feature is supported (it is an OpenGL 1.3 feature), an additional buffer is added to the framebuffer that includes the color, depth, and stencil values. All primitives are sampled multiple times per pixel, and the results are stored in this buffer.

First: you must obtain a rendering context that has support for a multisampled framebuffer.
setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::SampleBuffers));
Second: turn multisampling on or off:
glEnable(GL_MULTISAMPLE); // glDisable(GL_MULTISAMPLE);

Another important note about multisampling is that when it is enabled, the point, line, and polygon smoothing features are ignored if enabled. On a given OpenGL implementation, points and lines may look better with smoothing turned on instead of multisampling.
实体图形效果非常的好啊, 比使用前面的antialiasing好非常多. 而且就上面两步搞定. 但对于点和线来说, 使用smoothing的效果却比multisampling的效果好, 所以要看情况来定.
posted on 2009-05-23 15:14 逛奔的蜗牛 阅读(2411) 评论(2)  编辑 收藏 引用 所属分类: OpenGL

评论

# re: OpenGL: 反锯齿 2012-07-30 14:47 外星人
setFormat是哪里有?是哪个库的?  回复  更多评论
  

# re: OpenGL: 反锯齿 2012-07-30 14:48 外星人
setFormat在哪个库文件?  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理