使用 DDS 压缩图像在 OpenGL 中进行立方体映射?
我在使用 DDS 立方体贴图时遇到立方体映射问题,我只是得到一个黑色立方体,这让我相信我错过了一些简单的东西,这是到目前为止的代码:
DDS_IMAGE_DATA *pDDSImageData = LoadDDSFile(filename);
//compressedTexture = -1;
if(pDDSImageData != NULL)
{
int height = pDDSImageData->height;
int width = pDDSImageData->width;
int numMipMaps = pDDSImageData->numMipMaps;
int blockSize;
GLenum cubefaces[6] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
};
if( pDDSImageData->format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT )
blockSize = 8;
else
blockSize = 16;
glGenTextures( 1, &textureId ); int nSize;
int nOffset = 0;
glEnable(GL_TEXTURE_CUBE_MAP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
for(int face = 0; face < 6; face++)
{
for( int i = 0; i < numMipMaps; i++ )
{
if( width == 0 ) width = 1;
if( height == 0 ) height = 1;
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
nSize = ((width+3)>>2) * ((height+3)>>2) * blockSize;
glCompressedTexImage2D(cubefaces[face] ,
i,
pDDSImageData->format,
width,
height,
0,
nSize,
pDDSImageData->pixels + nOffset );
nOffset += nSize;
// Half the image size for the next mip-map level...
width = (width / 2);
height = (height / 2);
}
}
}
调用此代码后,我使用 glBindTexture 绑定纹理并使用 GL_QUADS 和 glTexCoord3f 绘制立方体。
I am having trouble cube mapping when using a DDS cube map, I'm just getting a black cube which leads me to believe I have missing something simple, here's the code so far:
DDS_IMAGE_DATA *pDDSImageData = LoadDDSFile(filename);
//compressedTexture = -1;
if(pDDSImageData != NULL)
{
int height = pDDSImageData->height;
int width = pDDSImageData->width;
int numMipMaps = pDDSImageData->numMipMaps;
int blockSize;
GLenum cubefaces[6] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
};
if( pDDSImageData->format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT )
blockSize = 8;
else
blockSize = 16;
glGenTextures( 1, &textureId ); int nSize;
int nOffset = 0;
glEnable(GL_TEXTURE_CUBE_MAP);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,
GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
for(int face = 0; face < 6; face++)
{
for( int i = 0; i < numMipMaps; i++ )
{
if( width == 0 ) width = 1;
if( height == 0 ) height = 1;
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_GENERATE_MIPMAP, GL_TRUE);
nSize = ((width+3)>>2) * ((height+3)>>2) * blockSize;
glCompressedTexImage2D(cubefaces[face] ,
i,
pDDSImageData->format,
width,
height,
0,
nSize,
pDDSImageData->pixels + nOffset );
nOffset += nSize;
// Half the image size for the next mip-map level...
width = (width / 2);
height = (height / 2);
}
}
}
Once this code is called I bind the texture using glBindTexture and draw a cube using GL_QUADS and glTexCoord3f.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在用一个多维数据集运行我的压缩 dds 文件。
您的代码是正确的,但是您是否从以下位置布局了飞机
你的立方体方向正确吗?
请记住,您在立方体中。
在你的显示例程中试试这个(用java):
I'm get running my compressed dds-files with a cube.
Your code is right, but have you layout your planes from
your cube in the right orientation?
Remember, you are IN the cube.
Try this in your display routine (in java):