views:

1071

answers:

3

How would I load a dds texture file into an OpenGL 2dtexture or cube map texture?

+2  A: 

I believe you use the glCompressedTexImage2DARB method and its friends.

This PDF seems to contain some promising info that may be helpful to you.

Dan Olson
A: 

If the DDS contains a compressed texture then use glCompressedTexImage2DARB(), if it contains uncompressed data the usual glTexImage2D procedure applies. Once for each mipmap level if the DDS file contains mipmaps, and once for each cubemap face if its a cubemap.

For how to go about reading the header and data in a DDS file look up the documentation for it on MSDN or in the DirectX SDK. It's a fairly standard container format, there aren't too many surprises.

Be aware that DDS uses a top-left image origin whereas OpenGL assumes a bottom-left origin for image data. This means you will probably want to vertically flip a DDS image after loading it in. You can do this without decompressing them if they are in DXT1/3/5, but it's a slightly fiddly process that involves bit manipulation on the contents of each 4x4 compression block.

richard_nz
+1  A: 

Depending on your needs, the DevIL library can take care of feeding OpenGL with a DDS file content.

rotoglup