计算机通过离散(不连续)的像素来绘制图形,想象一下,真实世界中,我们画直线,是比连续画的,还是一个点一个点画的?计算机就是一个点一个点画的(很小的矩形).这样就会导致绘制的图形走样(锯齿),消除锯齿的技术就叫反走样(抗锯齿)
可以看这篇:http://blog.csdn.net/mikewolf2009/archive/2009/08/18/4460421.aspx
当点很大时,显示如下
而我们实际想看到的是一个圆点,而不是矩形
启用抗锯齿后的效果
有点圆了
代码
glPointSize(10); glEnable (GL_POINT_SMOOTH); glHint (GL_POINT_SMOOTH, GL_NICEST);
还是以glEnable来启用抗锯齿,可以根据不同图形进行处理
当然效果越好,那么计算机速度就越慢,即有一个参数设置
glHint用于对点,线,多边形的抗锯齿程度进行设置
未启用
启用后
很明显,启用抗锯齿后,粗线变成了矩形,而未启动则是一个平行四边形
代码
glEnable (GL_LINE_SMOOTH); glHint (GL_LINE_SMOOTH, GL_NICEST); glLineWidth (10);
其根据像素样本数量具有多种颜色,深度和多组纹理坐标来处理,特别适合多边形
三个步骤
1. Obtain a window that supports multisampling. With GLUT, you can ask for one by calling
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |
GLUT_MULTISAMPLE);
2. After you’ve opened a window, you will need to verify that multisampling
is available. For instance, GLUT may give you a window
with “almost” what you have asked for. If querying the state variable
GL_SAMPLE_BUFFERS returns a value of one and GL_SAMPLES returns
a value greater than one, then you’ll be able to use multisampling.
(GL_SAMPLES returns the number of subpixel samples. If there is only
one sample, multisampling is effectively disabled.)
GLint bufs, samples;
glGetIntegerv(GL_SAMPLE_BUFFERS, &bufs);
glGetIntegerv(GL_SAMPLES, &samples);
3. To turn on multisampling, call
glEnable(GL_MULTISAMPLE);
如下两图的比较
原文地址:http://blog.csdn.net/u013467442/article/details/40627717