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
}
|