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 是将二者相乘。

  • 相关阅读:
    ElasticSearch(站内搜索) 转发 https://www.cnblogs.com/xibei666/p/5929970.html
    【大型网站技术实践】初级篇:借助Nginx搭建反向代理服务器 转发 https://www.cnblogs.com/edisonchou/p/4126742.html
    Windows下Memcached在.Net程序中的实际运用(从Memcached客户端Enyim的库的编译到实际项目运用) 转发
    在Windows .NET平台下使用Memcached (Enyim使用)
    Enyim.Caching 客户端配置及示例
    Memcached 在windows环境下安装
    memcache讲解和在.net中初使用
    微信公众平台开发(68)苹果IMEI查询
    微信公众平台开发(70)经济指标财经大事
    微信公众平台开发(69)百度地图导航
  • 原文地址:https://www.cnblogs.com/qingsunny/p/3290972.html
Copyright © 2011-2022 走看看