# DXT compressed textures

**URL:** <https://community.khronos.org/t/dxt-compressed-textures/64785>\
**Category:** OpenGL: Basic Coding\
**Created:** [June 2, 2011, 11:14pm UTC](https://community.khronos.org/t/dxt-compressed-textures/64785 "2011-06-02T23:14:43Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![exiled](https://community.khronos.org/letter_avatar_proxy/v4/letter/e/9de053/32.png) [@exiled](https://community.khronos.org/u/exiled)\
**Post date:** [June 2, 2011, 11:14pm UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/1 "2011-06-02T23:14:43Z")

</div>

I am having some trouble loading compressed textures. I am following the source code which can be found here: [http://www.codesampler.com/oglsrc/oglsrc\_4.htm#ogl\_dds\_texture\_loader](http://www.codesampler.com/oglsrc/oglsrc_4.htm#ogl_dds_texture_loader)

```auto
for( int i = 0; i < bitmaps->mipmap; ++i )
    {
        if( nWidth == 0 ) nWidth = 1;
        if( nHeight == 0 ) nHeight = 1;

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

        ((PFNGLCOMPRESSEDTEXIMAGE2DARBPROC)wglGetProcAddress("glCompressedTexImage2D"))
			(GL_TEXTURE_2D, i, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, nWidth, nHeight, 0, nSize, (void*)((int)data + nOffset));

        nOffset += nSize;
        
        nWidth = (nWidth / 2);
        nHeight = (nHeight / 2);
    }

```

The first time it runs, glGetError return 1280 (invalid enum) than the other times it runs for rest of the mipmaps it returns 0.

---

<div class="post-metadata">

**Author:** ![Alfonse\_Reinheart](https://community.khronos.org/user_avatar/community.khronos.org/alfonse_reinheart/32/4357_2.png) [@Alfonse\_Reinheart](https://community.khronos.org/u/Alfonse_Reinheart)\
**Post date:** [June 2, 2011, 11:59pm UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/2 "2011-06-02T23:59:48Z")

</div>

Are you sure that this is the line that causes the error? Are you sure it isn’t a previous line that caused it?

---

<div class="post-metadata">

**Author:** ![ZbuffeR](https://community.khronos.org/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@ZbuffeR](https://community.khronos.org/u/ZbuffeR)\
**Post date:** [June 3, 2011, 12:20am UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/3 "2011-06-03T00:20:25Z")

</div>

Did you check your GL driver actually supports GL\_ARB\_texture\_compression ?

---

<div class="post-metadata">

**Author:** ![Dark\_Photon](https://community.khronos.org/user_avatar/community.khronos.org/dark_photon/32/4349_2.png) [@Dark\_Photon](https://community.khronos.org/u/Dark_Photon)\
**Post date:** [June 3, 2011, 4:04am UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/4 "2011-06-03T04:04:57Z")

</div>

> [@ZbuffeR](#):
>
> Did you check your GL driver actually supports GL\_ARB\_texture\_compression ?

And further that it supports EXT\_texture\_compression\_s3tc.

To Alfonse’s comment, make sure that no GL error is present before you make this call. If there is, all bets are off – go fix that first.

Do you have a texture created and bound before you make this call?

---

<div class="post-metadata">

**Author:** ![exiled](https://community.khronos.org/letter_avatar_proxy/v4/letter/e/9de053/32.png) [@exiled](https://community.khronos.org/u/exiled)\
**Post date:** [June 3, 2011, 8:11am UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/5 "2011-06-03T08:11:39Z")

</div>

```auto
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

```

It seems that was the problem, when I changed GL\_LINEAR\_MIPMAP\_NEAREST to GL\_LINEAR the texture showed up, that seemed to be the cause of the error. I don’t see why it would be if someone could explain it for me that would be helpful.

---

<div class="post-metadata">

**Author:** ![danbartlett](https://community.khronos.org/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@danbartlett](https://community.khronos.org/u/danbartlett)\
**Post date:** [June 3, 2011, 9:35am UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/6 "2011-06-03T09:35:43Z")

</div>

If you are using GL\_LINEAR\_MIPMAP\_NEAREST, then you are using mipmapping + you need to load all mipmap levels from GL\_TEXTURE\_BASE\_LEVEL (initial value = 0) to GL\_TEXTURE\_MAX\_LEVEL (initial value = 1000), or until you have a 1x1 pixel image, or your texture won’t be mipmap complete and won’t display correctly. Changing it to GL\_LINEAR disables mipmapping, so only level 0 is used, and it doesn’t matter whether the texture is mipmap complete.

If your texture file doesn’t include all the mipmap images down to 1x1, you will either need to generate these missing levels somehow, or call:

```auto
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, bitmaps->mipmap-1);//not sure what bitmaps->mipmap represents, but might need special handling if (bitmaps->mipmap == 0) is allowed

```

Did you check for errors before the function was called, because if your glCompressedTexImage2D call was succeeding, which it must have done if the texture is visible, then the error is unexplained.

ps. I wouldn’t call wglGetProcAddress(“glCompressedTexImage2D”) every single time you want to get the glCompressedTexImage2D entry-point, but only call it once + store the value somewhere. It probably won’t have much effect when it comes to loading texture data, but there’s no point performing unnecessary ops.

---

<div class="post-metadata">

**Author:** ![exiled](https://community.khronos.org/letter_avatar_proxy/v4/letter/e/9de053/32.png) [@exiled](https://community.khronos.org/u/exiled)\
**Post date:** [June 3, 2011, 1:35pm UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/7 "2011-06-03T13:35:23Z")

</div>

Adding that did the trick

Also I know my card supports the compression along with my drivers but I couldn’t find the function to check if the card and the driver support the compression.

```auto
glGetString( GL_EXTENSIONS );

```

Would that be the function to use and than search for the string for example “ARB\_texture\_compression” ?

---

<div class="post-metadata">

**Author:** ![danbartlett](https://community.khronos.org/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@danbartlett](https://community.khronos.org/u/danbartlett)\
**Post date:** [June 3, 2011, 4:54pm UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/8 "2011-06-03T16:54:36Z")

</div>

Yes, but see also [http://www.opengl.org/wiki/GlGetString](http://www.opengl.org/wiki/GlGetString) , because there’s some situations you have to be careful of, such as incorrectly finding an extension because the name happens to be part of another extensions name:

eg: searching for “GL\_ARB\_fragment\_program” might be found inside “GL\_ARB\_fragment\_program\_shadow” or “GL\_EXT\_swap\_control” might be found inside “WGL\_EXT\_swap\_control”, you’d have to check that the start of the sub-string found either starts the whole extension string, or is preceded by a space. You also need to check that the end of the sub-string found is either the end of the extension string, or is followed by a space. With OpenGL 3.1+ it is recommended to use glGetStringi instead of glGetString.

---

<div class="post-metadata">

**Author:** ![Alfonse\_Reinheart](https://community.khronos.org/user_avatar/community.khronos.org/alfonse_reinheart/32/4357_2.png) [@Alfonse\_Reinheart](https://community.khronos.org/u/Alfonse_Reinheart)\
**Post date:** [June 3, 2011, 4:59pm UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/9 "2011-06-03T16:59:02Z")

</div>

Or you could avoid all this and just use an extension loading library.

---

<div class="post-metadata">

**Author:** ![RefleX](https://community.khronos.org/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@RefleX](https://community.khronos.org/u/RefleX)\
**Post date:** [June 4, 2011, 12:53pm UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/10 "2011-06-04T12:53:02Z")

</div>

EXT\_texture\_compression\_s3tc is almost guaranteed to be supported on your card, it’s ancient. Use [GLEW](http://glew.sourceforge.net/) to manage OpenGL extensions. You have to make sure that everything is set up correctly before a texture is usable. Make sure that all mipmap levels are loaded correctly and texture filtering is set correctly. You can have a look at the [OpenGL Registry](http://www.opengl.org/registry/), it contains a list of all the extensions and explains the conditions of using any extension.

---

<div class="post-metadata">

**Author:** ![dorbie](https://community.khronos.org/user_avatar/community.khronos.org/dorbie/32/53_2.png) [@dorbie](https://community.khronos.org/u/dorbie)\
**Post date:** [June 5, 2011, 3:28am UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/11 "2011-06-05T03:28:34Z")

</div>

It is not as widely available as one would like, depending on the platform you are on there can be licensing concerns. It is ancient, it is widely supported on Windows and it is patented and not licensed and intentionally avoided by some vendors on some platforms.

It’s a shame really, the technology in this texture compression was published as Color Cell Compression and Block Truncation Coding and even developed in parallel for texture compression at companies like SGI.

But some companies sidestep implementing it on all platforms because of S3 licensing fees / patent infringement.

---

<div class="post-metadata">

**Author:** ![dorbie](https://community.khronos.org/user_avatar/community.khronos.org/dorbie/32/53_2.png) [@dorbie](https://community.khronos.org/u/dorbie)\
**Post date:** [June 5, 2011, 3:34am UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/12 "2011-06-05T03:34:14Z")

</div>

The problem with the filter you selected is because MIPMAP filters are only applicable to minification. With magnification it makes no sense to request a mipmap filter.

---

<div class="post-metadata">

**Author:** ![RefleX](https://community.khronos.org/letter_avatar_proxy/v4/letter/r/f05b48/32.png) [@RefleX](https://community.khronos.org/u/RefleX)\
**Post date:** [June 5, 2011, 11:43am UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/13 "2011-06-05T11:43:58Z")

</div>

> [@dorbie](#):
>
> It is not as widely available as one would like, depending on the platform you are on there can be licensing concerns. It is ancient, it is widely supported on Windows and it is patented and not licensed and intentionally avoided by some vendors on some platforms.
> 
> It’s a shame really, the technology in this texture compression was published as Color Cell Compression and Block Truncation Coding and even developed in parallel for texture compression at companies like SGI.
> 
> But some companies sidestep implementing it on all platforms because of S3 licensing fees / patent infringement.

What platforms have support for s3tc and what are the licensing fees / patent infringements?

---

<div class="post-metadata">

**Author:** ![Dark\_Photon](https://community.khronos.org/user_avatar/community.khronos.org/dark_photon/32/4349_2.png) [@Dark\_Photon](https://community.khronos.org/u/Dark_Photon)\
**Post date:** [June 6, 2011, 5:05am UTC](https://community.khronos.org/t/dxt-compressed-textures/64785/14 "2011-06-06T05:05:20Z")

</div>

> [@RefleX](#):
>
> What platforms have support for s3tc and what are the licensing fees / patent infringements?

Here’s a start:

[http://feedback.wildfiregames.com/report/opengl/feature/GL\_EXT\_texture\_compression\_s3tc](http://feedback.wildfiregames.com/report/opengl/feature/GL_EXT_texture_compression_s3tc)

“Does support” is up-top in the green table. See the “red” table at the bottom for “does not support”.

So pretty much anything ATI, NVidia, or Intel on PC supports.
