# Texture compression

**URL:** <https://community.khronos.org/t/texture-compression/48596>\
**Category:** OpenGL\
**Tags:** linux\
**Created:** [June 6, 2007, 8:08am UTC](https://community.khronos.org/t/texture-compression/48596 "2007-06-06T08:08:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gremour](https://community.khronos.org/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gremour](https://community.khronos.org/u/Gremour)\
**Post date:** [June 6, 2007, 8:08am UTC](https://community.khronos.org/t/texture-compression/48596/1 "2007-06-06T08:08:00Z")

</div>

I’m trying to compress a texture using OpenGL glTexImage2D function. Everything works fine under Windows, but under Linux compression just doesn’t happen. I’ve made a simple test program to locate problem, here it is:

```auto
#define GLX_GLXEXT_PROTOTYPES

#include <GL/glx.h> // includes gl, glext
#include <GL/glu.h>
#include <stdio.h>
#include <string.h>

//----------------------------------------------------------------------------

int main (int argc, char *argv[])
{
    int attributes[] = 
    {
      GLX_RGBA,
      GLX_DOUBLEBUFFER,
      GLX_RED_SIZE, 8,
      GLX_GREEN_SIZE, 8,
      GLX_BLUE_SIZE, 8,
      GLX_DEPTH_SIZE, 24,
      0
    };
    Display *display = XOpenDisplay(NULL);
    if (!display)
    {
        printf ("Cannot open display.
");
        return 1;
    }
    XVisualInfo *vinfo = glXChooseVisual(display, DefaultScreen(display), attributes);
    if (!vinfo)
    {
        printf ("Cannot get visual.
");
        return 1;
    }
    GLXContext context = glXCreateContext(display, vinfo, 0, GL_TRUE);  

    XSetWindowAttributes winattrs;
    winattrs.event_mask = 0;
    winattrs.border_pixel = 0;
    winattrs.bit_gravity = StaticGravity;
    int winmask = CWBorderPixel | CWColormap | CWBitGravity | CWEventMask;

    Window rw = DefaultRootWindow(display);
    winattrs.colormap = XCreateColormap(display, rw, vinfo->visual, AllocNone); 
    Window window = XCreateWindow(display, rw,
                             0, 0, 100, 100, 0, vinfo->depth
                             ,InputOutput
                             ,vinfo->visual
                             ,winmask
                             ,&winattrs);

    glXMakeCurrent(display, window, context);

    // -------------- Compressing texture here ----------------

    unsigned char tx[] =
    {
	0x00, 0x00, 0xff, 0x00, 0xff, 0xff,
	0xff, 0xff, 0x00, 0x00, 0xff, 0x00
    };

// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_ARB, 2, 2,
            0, GL_BGR_EXT, GL_UNSIGNED_BYTE, tx);

    int compressed = -1;

    glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &compressed);

    printf ("Compressed = %d
", compressed);

    // ---------------------------------------------------------

    glXDestroyContext(display, context);
    XCloseDisplay (display);

    return 0;
}

```

It prints “Compressed = 0” (analoguous code returns 1 in “compressed” variable under Windows).

Printed list of extensions, which contains GL\_ARB\_texture\_compression. glTexImage2D produce “no error” code. Checked internal format of texture, it is equal to GL\_COMPRESSED\_RGB\_ARB, yet GL\_TEXTURE\_COMPRESSED\_IMAGE\_SIZE\_ARB returns zero.

All other GL functions works fine.

Could anyone say what’s happening, or at least point where to dig?

System: Fedora Core 6, gcc 4.1.1, Video Intel 945 (last drivers included in FC6, according to Intel)

---

<div class="post-metadata">

**Author:** ![Gremour](https://community.khronos.org/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gremour](https://community.khronos.org/u/Gremour)\
**Post date:** [June 6, 2007, 8:42am UTC](https://community.khronos.org/t/texture-compression/48596/2 "2007-06-06T08:42:00Z")

</div>

Forgot to mention, glXCreateContext always prints a warning:

libGL warning: 3D driver claims to not support visual 0x5b

0x5b is visual type for 32 bit (TrueColor), and my desktop uses 24 bit (vinfo-\>visualid == 0x25).

Wonder, may it have any relevance.

---

<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 6, 2007, 9:01am UTC](https://community.khronos.org/t/texture-compression/48596/3 "2007-06-06T09:01:00Z")

</div>

Maybe this is due to the patent on S3TC.  
[http://forum.worldwindcentral.com/showpo…20&postcount=16](http://forum.worldwindcentral.com/showpost.php?s=5bc126e09127900bc6a436475804b39e&p=45020&postcount=16)

GL\_ARB\_texture\_compression is not tied to a particular implementation, but the S3TC implementation is protected by a patent.

Check for the presence of GL\_EXT\_texture\_compression\_s3tc.

---

<div class="post-metadata">

**Author:** ![Gremour](https://community.khronos.org/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gremour](https://community.khronos.org/u/Gremour)\
**Post date:** [June 7, 2007, 1:48am UTC](https://community.khronos.org/t/texture-compression/48596/4 "2007-06-07T01:48:00Z")

</div>

Thanks.

GL\_EXT\_texture\_compression\_s3tc wasn’t in list of extensions under Linux. I’ve used driconf and enabled S3TC compression (even if software doesn’t support it – so it says) in driver (it was disabled). That extention now appears in list.

However, code above still do not work (returns 0 in compressed). ☹

Tried it also on machine with ATI Radeon 9550, Fedora Core 6.

---

<div class="post-metadata">

**Author:** ![Gremour](https://community.khronos.org/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gremour](https://community.khronos.org/u/Gremour)\
**Post date:** [June 7, 2007, 3:31am UTC](https://community.khronos.org/t/texture-compression/48596/5 "2007-06-07T03:31:00Z")

</div>

I’ve managed to make compression “work” by using GL\_COMPRESSED\_RGB\_S3TC\_DXT1\_EXT instead of GL\_COMPRESSED\_RGB\_ARB. However, I got another runtime warning:

Mesa 6.5.1 implementation error: external dxt library not available  
Please report at [bugzilla.freedesktop.org](http://bugzilla.freedesktop.org)

And resulting compressed texture (it have normal size, 1/6 of uncompressed) is filled with zeroes.

I have bad feeling that GL libs on mys system is outdated (how come?!). Here’s what I have in /usr/lib:

/usr/lib/libGL.so  
/usr/lib/libGL.so.1.2  
/usr/lib/libGLU.so.1  
/usr/lib/libGL.so.1  
/usr/lib/libGLU.so  
/usr/lib/libGLU.so.1.3.060501

A hint how to get latest GL libs and install them would be greatly appreciated.

Thanks in advance.

P.S. System also has these libs:  
/usr/lib/libdrm.so  
/usr/lib/libdrm.so.2  
/usr/lib/libdrm.so.2.0.0

And version string OpenGL returned:  
Version: 1.3 Mesa 6.5.1

---

<div class="post-metadata">

**Author:** ![PkK](https://community.khronos.org/letter_avatar_proxy/v4/letter/p/ecb155/32.png) [@PkK](https://community.khronos.org/u/PkK)\
**Post date:** [June 7, 2007, 9:26am UTC](https://community.khronos.org/t/texture-compression/48596/6 "2007-06-07T09:26:00Z")

</div>

> Originally posted by Gremour:  
> [b] Thanks.

> GL\_EXT\_texture\_compression\_s3tc wasn’t in list of extensions under Linux. I’ve used driconf and enabled S3TC compression (even if software doesn’t support it – so it says) in driver (it was disabled). That extention now appears in list.

> However, code above still do not work (returns 0 in compressed). ☹  
> [/b]  
> That’s normal: GL\_EXT\_texture\_compression\_s3tc was not in the extension string because it’s not completely supported. The driconf option is an override to support software that needs S3TC, but not all of it. Decompression is often implemented in hardware and that’s what most programs use.

---

<div class="post-metadata">

**Author:** ![PkK](https://community.khronos.org/letter_avatar_proxy/v4/letter/p/ecb155/32.png) [@PkK](https://community.khronos.org/u/PkK)\
**Post date:** [June 7, 2007, 9:31am UTC](https://community.khronos.org/t/texture-compression/48596/7 "2007-06-07T09:31:00Z")

</div>

> Originally posted by ZbuffeR:  
> Maybe this is due to the patent on S3TC.  
>    
> It is due to the patent. if you don’t care about it (or have a license or live somewhere where it’s not patented like in the EU) just download the libdxtn from R. Scheidegger at [http://homepage.hispeed.ch/rscheidegger/dri\_experimental/s3tc\_index.html](http://homepage.hispeed.ch/rscheidegger/dri_experimental/s3tc_index.html) ,install it and you’ll get full S3TC support.

Philipp

---

<div class="post-metadata">

**Author:** ![Gremour](https://community.khronos.org/letter_avatar_proxy/v4/letter/g/7ba0ec/32.png) [@Gremour](https://community.khronos.org/u/Gremour)\
**Post date:** [June 8, 2007, 4:50am UTC](https://community.khronos.org/t/texture-compression/48596/8 "2007-06-08T04:50:00Z")

</div>

I’ve ended up with precompressing textures under Windows.

Will take a look at the libtxc.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![system](https://community.khronos.org/uploads/default/original/2X/b/ba89cb49313a0e869198c8be354afde8bcae027e.png) [@system](https://community.khronos.org/u/system)\
**Post date:** [October 19, 2021, 6:44pm UTC](https://community.khronos.org/t/texture-compression/48596/9 "2021-10-19T18:44:20Z")

</div>

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.
