OpenGL载入DDS压缩纹理
2011-04-27 23:13
363 查看
网络上的图像库很多,如
FreeImage
、
Devil
等,库很强大且支持多种格式,当然也包括
DDS
纹理。例如
FreeImage
,但是它这里所说的支持
DDS
格式是指将压缩格式的数据重新解压成
RGBA
像素数据,将数据解压后再绑定到
OpenGL
中就失去了其作为压缩纹理的高效性(因
OpenGL
直接支持此压缩纹理数据)。
FreeImage
作者建议参考
Ogre
的
DDS
纹理载入实现,但那部分实现与
Ogre
切合太紧不便
Ogre
之外应用,需要的是一个方便的压缩纹理绑定函数。多方查找后发现
Nvidia
的一个小类库
nv_dds
挺好用的,就把它封装了一下,附上源码
(可根据实际需要扩充功能)。
/** DDS
纹理绑定函数
* @param[in] filePath
纹理路径
* @param[out] texID
纹理
ID
* @return
数据信息
* - 0
打开失败
* - 1 RGB
格式
* - 2 RGBA
格式
*/
unsigned
BuildDDS
(char
*filePath
, unsigned
&texID
)
{
nv_dds
::CDDSImage
image
;
if
(!image
.load
(string
(filePath
)))
{
return
0;
}
glGenTextures
(1,
&texID
);
glEnable
(GL_TEXTURE_2D
);
glBindTexture
(GL_TEXTURE_2D
, texID
);
glCompressedTexImage2D
(GL_TEXTURE_2D
, 0, image
.get_format
(),
image
.get_width
(), image
.get_height
(), 0, image
.get_size
(), image
);
for
(int
i
= 0; i
< image
.get_num_mipmaps
(); i
++)
{
glCompressedTexImage2D
(GL_TEXTURE_2D
, i
+1,
image
.get_format
(),
image
.get_mipmap
(i
).get_width
(), image
.get_mipmap
(i
).get_height
(), 0,
image
.get_mipmap
(i
).get_size
(), image
.get_mipmap
(i
));
}
return
image
.get_components
()
< 4 ? 1 : 2;
}
源码中使用到了
glext.h
头文件、
glut
和
glew
两个
OpenGL
相关库,需自行添加到
VC2010
的相关目录中,同时将
dds
纹理置于
C
盘或自行修改路径。
FreeImage
、
Devil
等,库很强大且支持多种格式,当然也包括
DDS
纹理。例如
FreeImage
,但是它这里所说的支持
DDS
格式是指将压缩格式的数据重新解压成
RGBA
像素数据,将数据解压后再绑定到
OpenGL
中就失去了其作为压缩纹理的高效性(因
OpenGL
直接支持此压缩纹理数据)。
FreeImage
作者建议参考
Ogre
的
DDS
纹理载入实现,但那部分实现与
Ogre
切合太紧不便
Ogre
之外应用,需要的是一个方便的压缩纹理绑定函数。多方查找后发现
Nvidia
的一个小类库
nv_dds
挺好用的,就把它封装了一下,附上源码
(可根据实际需要扩充功能)。
/** DDS
纹理绑定函数
* @param[in] filePath
纹理路径
* @param[out] texID
纹理
ID
* @return
数据信息
* - 0
打开失败
* - 1 RGB
格式
* - 2 RGBA
格式
*/
unsigned
BuildDDS
(char
*filePath
, unsigned
&texID
)
{
nv_dds
::CDDSImage
image
;
if
(!image
.load
(string
(filePath
)))
{
return
0;
}
glGenTextures
(1,
&texID
);
glEnable
(GL_TEXTURE_2D
);
glBindTexture
(GL_TEXTURE_2D
, texID
);
glCompressedTexImage2D
(GL_TEXTURE_2D
, 0, image
.get_format
(),
image
.get_width
(), image
.get_height
(), 0, image
.get_size
(), image
);
for
(int
i
= 0; i
< image
.get_num_mipmaps
(); i
++)
{
glCompressedTexImage2D
(GL_TEXTURE_2D
, i
+1,
image
.get_format
(),
image
.get_mipmap
(i
).get_width
(), image
.get_mipmap
(i
).get_height
(), 0,
image
.get_mipmap
(i
).get_size
(), image
.get_mipmap
(i
));
}
return
image
.get_components
()
< 4 ? 1 : 2;
}
源码中使用到了
glext.h
头文件、
glut
和
glew
两个
OpenGL
相关库,需自行添加到
VC2010
的相关目录中,同时将
dds
纹理置于
C
盘或自行修改路径。
相关文章推荐
- OpenGL 加载DDS文件(压缩纹理)
- opengl利用SOIL加载图片dds纹理
- OpenGL纹理压缩
- OpenGL载入图片作为纹理
- 读取dds文件转为opengl纹理
- 在OpenGL中使用纹理压缩
- wp8下压缩纹理的使用(dds)
- wp8下压缩纹理的使用(dds)
- OpenGL蓝宝书源码学习(十)第五章——纹理的应用、Mip贴图、各项异性过滤和纹理压缩基础
- openGL纹理压缩概括
- 纹理压缩(Texture compression) -- DDS
- C#+OpenGL编程之OpenGL 纹理载入
- 关于大四上学期的计算机图形学实验报告123——opengl建模、载入OBJ文件、纹理贴图、光照、交互。
- 纹理压缩(Texture compression) -- DDS
- opengl使用 devil载入纹理
- 在OpenGL中使用纹理压缩
- 读取dds文件转为opengl纹理
- 不用AuxDIBImageLoad()向opengl中载入bmp纹理
- android opengl压缩纹理读入
- glew,glfw实现最新的opengl-学习笔记4实现纹理