zoukankan      html  css  js  c++  java
  • OpenGL学习笔记(10)抗锯齿

           计算机通过离散(不连续)的像素来绘制图形,想象一下,真实世界中,我们画直线,是比连续画的,还是一个点一个点画的?计算机就是一个点一个点画的(很小的矩形).这样就会导致绘制的图形走样(锯齿),消除锯齿的技术就叫反走样(抗锯齿)

    可以看这篇:http://blog.csdn.net/mikewolf2009/archive/2009/08/18/4460421.aspx

    点示例

    当点很大时,显示如下

    image

    而我们实际想看到的是一个圆点,而不是矩形

    启用抗锯齿后的效果

    image

    有点圆了微笑

    代码

    glPointSize(10);
    glEnable (GL_POINT_SMOOTH);
    glHint (GL_POINT_SMOOTH, GL_NICEST);

    启用抗锯齿

    还是以glEnable来启用抗锯齿,可以根据不同图形进行处理

    1. GL_POINT_SMOOTH 点
    2. GL_LINE_SMOOTH 线
    3. GL_POLYGON_SMOOTH 多边形

    抗锯齿质量

    当然效果越好,那么计算机速度就越慢,即有一个参数设置

    glHint用于对点,线,多边形的抗锯齿程度进行设置

    1. GL_DONT_CARE 放弃,应该是系统默认吧
    2. GL_FASTEST 速度优先
    3. GL_NICEST 图形显示质量优先

    线示例

    未启用

    image

    启用后

    image

    很明显,启用抗锯齿后,粗线变成了矩形,而未启动则是一个平行四边形

    代码

    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);

    如下两图的比较

    image

    image

    这些功能由OpenGL内置支持

  • 相关阅读:
    << 和>> 的计算公式
    死锁面试题(什么是死锁,产生死锁的原因及必要条件)
    SpringBoot的注解:@SpringBootApplication注解 vs @EnableAutoConfiguration+@ComponentScan+@Configuration
    SpringBoot入门-15(springboot配置freemarker使用YML)
    shiro 登录
    springMVC RedirectAttributes
    IDEA3.5最新版激活码
    求递归算法时间复杂度:递归树
    渐进复杂度
    PL/SQL注册码
  • 原文地址:https://www.cnblogs.com/Clingingboy/p/1861660.html
Copyright © 2011-2022 走看看