How to use compressed textures with OpenGL

… in Java of course. Jogl to be more precise. I guess my question is pretty similar to Lwjgl so I’m posting this here, not into the Jogl forum.

A [quote]gl.isExtensionAvailable(“GL_ARB_texture_compression”)
[/quote]
gives true for my card so I thought it’s safe to call this (in order to bind my RGB texture):

[quote]gl.glCompressedTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_COMPRESSED_RGB,
xdim, ydim, 0, GL.GL_UNSIGNED_BYTE size, bytearray);
[/quote]
but I’m prompted with an error.
(Using glTexImage2D(…) with GL_RGB as internalformat and format works, but not compressed of course.)

http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_compression.txt doesn’t help me either. Googling brings references to the above URL.

{Edit: Use compressed ! size}

This is how I display DXT compressed textures with my DDS loader :


      if(pixelFormat.isDXT())
      {
            boolean supported = true;
            int compressedFormat = 0;
                  
            switch(pixelFormat.getDXTVersion())
            {
                  case 1 : 
                        compressedFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; break;
                  case 3 : 
                        compressedFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; break;
                  case 5 : 
                        compressedFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; break;
                  default : 
                        supported = false; break;
            }
                  
            if(supported)
            {
                  int size = image.getSize(); //return the total size of the compressed texture
                  gl.glCompressedTexImage2D(GL_TEXTURE_2D, 0, compressedFormat, width, height, 0, size, pixels);
            }
      }

Your problem is that the ‘size’ argument should be the total compressed size of the texture, not its storage type. At least that’s how it works with DXT :slight_smile:

Thanks for the hints…
So it’s not really as simple to implement as I thought (but then, it’s never when you do raw OpenGL…).

So actually you use the GL_EXT_texture_compression_s3tc extension then?
What’s with the GL_ARB_texture_compression? How can I compress a texture so that it can be used with this extension? {Edit} Use one of those tools at Ati/Nvidia/blabla to lossy compress it.

Extensions - an alien world to me. :slight_smile:

Well there is only one parameter to change. :slight_smile:

However I don’t know how it works with GL_COMPRESSED_{RGB, RGBA, ALPHA, …} : I only used it with DXT and I don’t plan to support any other method at the moment. DXT compressed DDS textures are definitely great : having all mipmap levels and/or cubemap faces stored in a single file with high compression ratio is invaluable.

Though I wish Nvidia had respected MS specs with their DDS exporter : now a lot of DDS files have wrong header and size, which makes it difficult to write a stable loader. >:(

[quote]So actually you use the GL_EXT_texture_compression_s3tc extension then?
What’s with the GL_ARB_texture_compression? How can I compress a texture so that it can be used with this extension? {Edit} Use one of those tools at Ati/Nvidia/blabla to lossy compress it.
[/quote]
Yes you should use Nvidia plugin (either with photoshop or command-line). It is safe for DXT. Since I mostly played with Far Cry textures so far, I haven’t created my own DDS files yet.

[quote]Extensions - an alien world to me. :slight_smile:
[/quote]
Me too. I got part of the code from CodeSampler’s DDS loader and added some missing stuff. ;D