Textures are usually a heavily used resource in a game, and theres alot of them. In this tutorial, we will compress the texture data to obtain maximum of 8:1 compression ratio.
There are a few compression schemes, the first one was created by S3, and the extension is hence called S3TC (S3 Texture Compression). It comes in a few flavours depending on the compression type and what the data is. Im going to concentrate on DXT1, DXT1A, DXT3 and DXT5 and all 4 are lossy and not suitable for normal maps (3Dc is used for normal maps).
You have two choices with the textures, you can either load the data pre-compressed and tell the GL that the data we're sending through is already compressed (like DDS), or we can let the GL compress the textures for us; I'll concentrate on the latter as the former is out of the scope of this tutorial.
There are 6 GLEnums that are important, and they come from 2 extensions; EXT_Texture_Compression_S3TC and ARB_Texture_Compression:
The latter two allow the GL to decide which method of compression is best suited, but the S3TC compression schemes have been very well adopted, and theres no reason to specify them specifically if you wanted to (providing the extensions are available).
The above constants are used as the arguments in the <internalformat> parameter of glTexImage2D, like so:
GL11.glTexImage2D(GL_TEXTURE_2D, 0, COMPRESSION_CONSTANT, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, myByteBuffer);
The above call specifies that you would like to compress mipmap level 0 of the currently bound texture using the COMPRESSION_CONSTANT compression scheme (replace it with any of the above constants).
Texture compression allows you to fit up to 8 times more textures in the same space, and thats a big plus whichever way you look at it. This one was easy wasn't?