zoukankan      html  css  js  c++  java
  • 纹理映射相关函数解析

     
     glGenTextures(1, &texObj); 
    
       glBindTexture(GL_TEXTURE_2D, texObj); 
    
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 
    
       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 
                      0, GL_RGBA, GL_UNSIGNED_BYTE, texImage); 
    texObj是用于存储从将作为纹理的图片的值以及后面对这个texture的paramener的设置。在设置texture的参数时,我们必须先将这个纹理作为current texture,而
    glBindTexture就是用于实现这一功能的。

    glEnable(GL_TEXTURE_2D); 
    
       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 
       glBindTexture(GL_TEXTURE_2D, texObj); 
    
       glBegin(GL_QUADS); 
         glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); 
         glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0); 
         glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0); 
         glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0); 
         glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0); 
         glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0); 
         glTexCoord2f(1.0, 1.0); glVertex3f(2.4, 1.0, -1.4); 
         glTexCoord2f(1.0, 0.0); glVertex3f(2.4, -1.0, -1.4); 
       glEnd(); 

    这里的glTexEnvf用于设置fragment原始的值与从texture mapping中获得的值的结合方式。因为fragment在rasterization的阶段用了顶点进行差值(顶点的值在vertex processing的阶段用了lighting computation进行了计算),然后texture mapping之后,这些fragment又获得了值,然后要考虑从lighting computation获得的值与从texture mapping获得的值如何结合。

    Secondary Colors
     A fragment may have a primary color and a secondary
    color
     If lighting is enabled
     Primary color contains ambient and diffuse contributions
    Secondary color contains specular contribution
     Texture color are applied to primary color (according to texture function)
     Secondary color is added to the post-texturing fragment color

    Useful for producing more realistic specular highlights, which could avoid effect(效果) of specular highlight are reduced as combine with texture value.

    the mode to combine the result of lighting computation and texture mapping value are setting by the following function:

     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, f)

    f is the the specific mode which could be GL_DECAL, GL_REPLACE, GL_MODULATE, GL_BLEND, GL_ADD or GL_COMBINE.

    常用的是 GL_REPLACE 和 GL_MODULATE

    GL_REPLACE 是用纹理值替代lighting computation的值,

    GL_MODULATE 是将二者相乘。

  • 相关阅读:
    Linux环境下配置Google Test、TBB、OpenMP和OpenCV
    构建一个真实的应用电子商务SportsStore(六)
    编写简单的c运行库(一)
    构建一个真实的应用电子商务SportsStore(七)
    Entity Framework性能测试
    C++在VS下创建、调用dll
    Contextfree Grammar的编译器设计和实现
    XP方法概述
    项目代码风格要求
    WCF学习 第三天 事务的使用
  • 原文地址:https://www.cnblogs.com/qingsunny/p/3290972.html
Copyright © 2011-2022 走看看