最近在工程中遇到的问题:在绘制图形时,直线会出现明显的锯齿,图形极不美观。使用抗锯齿之后,图形有了明显的变化。
抗锯齿的主要方法如下:
当点很大时,显示如下
而我们实际想看到的是一个圆点,而不是矩形
启用抗锯齿后的效果
有点圆了
代码
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);
如下两图的比较
这些功能由OpenGL内置支持