纹理滤波(Texture Filter)


0 原始贴图

1 Nearest滤波纹理

2 线性滤波纹理

3 MipMapped纹理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
int  LoadGLTextures()   // 载入位图(调用上面的代码)并转换成纹理
{
     int  Status=FALSE;        // 状态指示器
     AUX_RGBImageRec *TextureImage[1];        // 创建纹理的存储空间
     memset (TextureImage,0, sizeof ( void  *)*1);     // 将指针设为 NULL
     
     // 载入位图,检查有错,或位图不存在的话退出
     if  (TextureImage[0]=LoadBMP( "E:/OpenSource/Nehe/code/07_FilterAndLight/Debug/Data/Crate.bmp" ))
     {
         Status=TRUE;                 // 状态设为 TRUE
         glGenTextures(3, &texture[0]);   // 创建纹理
         // 创建 Nearest 滤波贴图
         glBindTexture(GL_TEXTURE_2D, texture[0]);
         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
         glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
 
         // 创建线性滤波纹理
         glBindTexture(GL_TEXTURE_2D, texture[1]);
         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, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
 
         // 创建 MipMapped 纹理
         glBindTexture(GL_TEXTURE_2D, texture[2]);
         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
         glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
         gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
     }
 
     if  (TextureImage[0])         // 纹理是否存在
     {
         if  (TextureImage[0]->data)    // 纹理图像是否存在
         {
             free (TextureImage[0]->data);  // 释放纹理图像占用的内存
         }
 
         free (TextureImage[0]);           // 释放图像结构
     }
     return  Status;                       // 返回 Status
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值