Problem cube mapping in OpenGL using DDS compressed images
- by Paul Jones
Hi All,
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.
Thank you for reading and all comments are welcome, sorry if any of the formatting comes out wrong.