This topic is now archived and is closed to further replies.


Can't load dds files

Recommended Posts

Hi, I finally managed to read the dds header.. but the dds loading code posted by Nvidia seems to calculate the image size wrong.
int *bufsize;
unsigned char *pixels;

        case FOURCC_DXT1:
            img->encoding = S3TC_RGBA_DXT1;
            factor = 2;
        case FOURCC_DXT3:
            img->encoding = S3TC_RGBA_DXT3;
            factor = 4;
        case FOURCC_DXT5:
            img->encoding = S3TC_RGBA_DXT5;
            factor = 4; // I found out that DXT5 compresses one color to 4 bits or something like that 

           return NULL;

//the code below should calculate the correct size of the pixel data in the dds file: 

*bufsize = ddsd.dwMipMapCount > 1 ? ddsd.dwLinearSize * factor : ddsd.dwLinearSize;
pixels = (unsigned char*)malloc(*bufsize * sizeof(unsigned char));
fread(pixels, 1, *bufsize, fp);
1024x512+32 bytes original tga file=> 699.216 bytes saved as dds with DXT5.. So *bufsize should be about 699.000 bytes ... but *bufsize is 2MB ..... ?? Why ? Edited by - TheMummy on November 1, 2001 8:12:13 AM Edited by - TheMummy on November 1, 2001 12:56:21 PM

Share this post

Link to post
Share on other sites
Me 2 !!
But the uncompressed tga image has a size of around 1,577 kbytes...
In the dds file there are 11 mipmaps of the original picture ... In the Nvidia tutorial they talked about loading theses maps directly to OpenGL...

The file is ok ... I already tested it with Photoshop...

I haven''t tried to load theses mipmaps to OpenGL .. I thouhgt about loading them and packing them together into my own little texture format ... So even when I find a dirty workaround for this problem, I will have to find the beginning of the mipmaps in the file later on, to get them into texture memory correctly ...

Share this post

Link to post
Share on other sites
i downloaded some other DXT related code from Nvidia and it seems that the ddsd.dwLinearSize is the size of the first biggest mipmap ...

When I can''t fix that problem I will have to generate the compressed textures on my own .... Howto?

Share this post

Link to post
Share on other sites
Ok I finally found the correct size calculation for S3TC mipmaps:

unsigned int allMipmaps = 0;
unsigend int blockSize = (format == FOURCC_DXT1) ? 8 : 16;

for(unsigned int i=0;i<ddsd.dwMipMapCount; i++)
if(Width == 0) Width = 1;
if(Height == 0) Height = 1;

// add the size of this MipMap:

allMipmaps += ( (Width+3 ) /4) * ( (Height + 3) /4) * blockSize;

// reduce size of image for next mipmap

Height >>= 1;
Width >>= 1;


In the first iteration step width and height are set to the original picture
width and height...

I don''t understand why there is ''+3'' but ... it works ...

Share this post

Link to post
Share on other sites