PDA

View Full Version : Compressed texture



aronsatie
07-31-2009, 04:46 PM
Hi,

This is the first time I am trying to use compressed textures (either GL_COMPRESSED_RGB_S3TC_DXT1_EXT for RGB or GL_COMPRESSED_RGBA_S3TC_DXT5_EXT for RGBA images). I pre-compress the images and save them to disk then I load them when I need them in compressed form.

Somehow I end up with a texture with only blue colours in it.

This is the way I compress my textures:



glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);

if (Texbpp<32)
glTexImage2D(GL_TEXTURE_2D,0,GL_COMPRESSED_RGB_S3T C_DXT1_EXT,Texwidth,Texheight,
0,GL_RGB,GL_UNSIGNED_BYTE,(GLvoid*)Texbytes);
else
glTexImage2D(GL_TEXTURE_2D,0,GL_COMPRESSED_RGBA_S3 TC_DXT5_EXT,Texwidth,Texheight,
0,GL_RGBA,GL_UNSIGNED_BYTE,(GLvoid*)Texbytes);

GLint compressed, internalformat,compressed_size;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_ARB, &amp;compressed);
if (compressed == GL_TRUE)
{
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, &amp;internalformat);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB,&amp;compressed_s ize);
glGetCompressedTexImageARB(GL_TEXTURE_2D, 0, TexbytesCompressed);
TexlengthCompressed=(int)compressed_size;
//SaveTexture(width, height, compressed_size, img, internalFormat, 0);
}
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTextures(1, &amp;tex);




And this is how I upload a compressed texture:





glBindTexture(GL_TEXTURE_2D, Tex);

if (BPP==24)
format=GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
else
format=GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;

glCompressedTexImage2D(GL_TEXTURE_2D,0,format, Xres,Yres,0,compressed_size,Data);


glBindTexture(GL_TEXTURE_2D, 0);


Do you see anything in these snippets that would explain why the R and G channels disappear from every pixel and only the B remains?

Thanks.