纹理映射相关函数解析

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

 

转载于:https://www.cnblogs.com/qingsunny/p/3290972.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值