我在使用 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 绘制立方体。