Sign in to follow this  
MARS_999

.dds file format any heads up I should know...

Recommended Posts

I am currently using .tga files and am thinking you can't use .tga for cubemaps? or 3D textures? Is that correct? If so can one just code up a loader for .dds files or is it locked out? Also how hard is it to code a .dds loader? Thanks

Share this post


Link to post
Share on other sites
you can get DDS working right from the specs over at MSDN I've done that myself and it's really not that hard, but I think there's free image loading libraries with DDS support available too, [google] can probably help you.

Share this post


Link to post
Share on other sites
Quote:
Original post by DigitalDelusion
you can get DDS working right from the specs over at MSDN I've done that myself and it's really not that hard, but I think there's free image loading libraries with DDS support available too, [google] can probably help you.


Thanks, but what about cubemap or 3D texture support in .tga files???

Share this post


Link to post
Share on other sites
DDS is pretty easy, the spec are over on the MSDN site as DigitalDelusion said (DSS loader).

I'd beware of the free image loaders however, FreeImage looks like it decompresses them! and doesnt look like it has sane support for mipmaps/cubemaps/3d textures. God knows what DevIL does with them (the interface put me off looking much further), afaik SDL_Image doesnt support them and Corona doesnt either.

I have plans afoot to get my own image loader supporting DDS + other image types working, however I'm a bit behind where I wanted to be right now and I dare say you cant wait [grin]. If ya intrested however keep an eye on my journal as I'll be waffling about it from time to time...

edit: tga are just normal 2d images

Share this post


Link to post
Share on other sites
edit: seems like my guesstimate was um, well crap so ignore this post.
Quote:
Original post by MARS_999
Thanks, but what about cubemap or 3D texture support in .tga files???


I haven't actually experimented with cubemaps or had the need for 3D textures myself so I can't help you with that. But basicly there shouldn't be a problem, I seriously can't imagine one anyhow, sure maybe you would need to convert to some funky data layout or something but that seems a bit, well, strange too.

A 3D texture should just be a lot of 2D ones stacked so that shouldn't be a problem and a cube map as far as I know isn't anything more complex than 6diffrent textures (one for each cube side) stored togheter.

I could be way off though.

Share this post


Link to post
Share on other sites

bool cTexture::LoadDDS(const char *filename)
{
DDSURFACEDESC2 ddsd;
char filecode[4];
int factor;
int bufferSize;
int format;
FILE *file=NULL;

file = fopen(filename, "rb");

// Verify the file is a true .dds file
fread(&filecode, 1, 4, file);
if( strncmp( filecode, "DDS ", 4 ) != 0 )
{
DebugManager->Print(Error, __FUNCTION__, "\"%s\" is not a valid .dds file !", filename);
return false;
}


// Get the surface descriptor
fread(&ddsd, 1, sizeof(ddsd), file);


//
// Type de compression
switch(ddsd.ddpfPixelFormat.dwFourCC)
{
case FOURCC_DXT1:
// DXT1's compression ratio is 8:1
format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
factor = 2;
break;

case FOURCC_DXT3:
// DXT3's compression ratio is 4:1
format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
factor = 4;
break;

case FOURCC_DXT5:
// DXT5's compression ratio is 4:1
format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
factor = 4;
break;

default:
TODO("The file \"%s\" doesn't appear to be compressed using DXT1, DXT3, or DXT5!", filename);
fclose(file);
return false;
break;
}

//
// Taille du buffer
//
if(!ddsd.dwLinearSize)
{
DebugManager->Print(Error, __FUNCTION__, "ddsd.dwLinearSize is 0 !");
fclose(file);
return false;
}
if (ddsd.dwMipMapCount > 1) bufferSize = ddsd.dwLinearSize * factor;
else bufferSize = ddsd.dwLinearSize;
ImageData = new unsigned char[bufferSize];
memset(ImageData, 0, bufferSize);
int ret = 0;
ret = fread(ImageData, 1, bufferSize, file);
fclose(file);

// Sauvegarde les infos
Width = ddsd.dwWidth;
Height = ddsd.dwHeight;
if(ddsd.ddpfPixelFormat.dwFourCC == FOURCC_DXT1 ) PixelFormat = PF_RGB;
else PixelFormat = PF_RGBA;


//
// Generation de la texture
glGenTextures(1, (GLuint *)&GLid);
glBindTexture(GL_TEXTURE_2D, GLid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );



// Chargement des mipmaps
int nSize = 0;
int nOffset = 0;
int nHeight = Height;
int nWidth = Width;
int nNumMipMaps = ddsd.dwMipMapCount;
int nBlockSize = format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ? 8 : 16;

for( unsigned long i = 0; i < ddsd.dwMipMapCount; ++i )
{
if( nWidth == 0 ) nWidth = 1;
if( nHeight == 0 ) nHeight = 1;

nSize = ((nWidth+3)/4) * ((nHeight+3)/4) * nBlockSize;

glCompressedTexImage2DARB( GL_TEXTURE_2D,
i,
format,
nWidth,
nHeight,
0,
nSize,
ImageData + nOffset );

nOffset += nSize;

// Moitie de la taille pour le prochain mipmap...
nWidth /= 2;
nHeight /= 2;
}


return true;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
I'd beware of the free image loaders however, FreeImage looks like it decompresses them!
Pardon my ignorance, but isn't that what you want the image loader to do, decompress the image and load it into a buffer/surface/whatever-you-use-in-API-of-choice?

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
I'd beware of the free image loaders however, FreeImage looks like it decompresses them! and doesnt look like it has sane support for mipmaps/cubemaps/3d textures.


Um, that's like exactly what Im doing to... OTOH I need them for pixel purposes so I really can't do it any other way but just out of curiosity how do you get OGL to actually swallow the compressed data? Im guessing extension but which one?

Share this post


Link to post
Share on other sites
@benryves

not really, its fine for general image mipulation but given that both D3D and OGL can deal with DXT compressed textures directly. Stuff like PNG/JPG/etc needs to be converted however,its just with DDS it makes no sense when working on a game.

@DigitalDelusion

The GL_ARB_texture_compression extension allows you to load data directly to the gfx card if its supported (it was promoted to core in OpenGL 1.3 so should be widely avaiable), and both NV and ATI cards have excellent support for DXT compressed textures ofcourse. It also supports ATI's normal map compression (ATI X800 and NV G70 cards onwards).

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
@DigitalDelusion

The GL_ARB_texture_compression extension allows you to load data directly to the gfx card if its supported (it was promoted to core in OpenGL 1.3 so should be widely avaiable), and both NV and ATI cards have excellent support for DXT compressed textures ofcourse. It also supports ATI's normal map compression (ATI X800 and NV G70 cards onwards).


Ah, wonderful! thanks.

Share this post


Link to post
Share on other sites
Quote:
I am currently using .tga files and am thinking you can't use .tga for cubemaps?

nothing stops u using a tga jpg whatever to create a cubemap heres one way i do it
GLuint givemecubemapTexture( const char sides[6][256], const GLint wr

u pass in 6 different textures for the sides

Share this post


Link to post
Share on other sites
So what texture format is everyone here using for cubemaps as their format? Yeah Phantom get in gear!! ;) I myself have limited time as for I work 7 days a week and do not have much time to code...

Share this post


Link to post
Share on other sites
For cube maps, you can save 6 separate TGA images. I've done this before; just find the "." and insert _+x, _-x, _+y etc before the period, so you end up with "forestbox_+x.tga," "forestbox_-x.tga", ...

However, I use DDS for everything, because that's the only format that stores DXT1/DXT5 data. You want to NOT decompress DXT1; instead, you want to create a compressed texture and put the data directly to the card; this makes texturing much faster (as there's less bits to read per texel).

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
So what texture format is everyone here using for cubemaps as their format? Yeah Phantom get in gear!! ;) I myself have limited time as for I work 7 days a week and do not have much time to code...


*chuckles* I'm working on it [grin], hopefully I get a bit done tonight before I goto bed and then I'll get on it tomorrow (my distraction is out of town)

Share this post


Link to post
Share on other sites
Quote:
Original post by _the_phantom_
Quote:
Original post by MARS_999
So what texture format is everyone here using for cubemaps as their format? Yeah Phantom get in gear!! ;) I myself have limited time as for I work 7 days a week and do not have much time to code...


(my distraction is out of town)


LOL A.K.A. Wife/Girlfriend...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this