This function is load a Lithtech *.dtx texture file and convert to OpenGL pixel format, compressed support.
Use FileSystem interface. :D
1 #pragmaPack (1)2 3 structDtxheader4 {5UnsignedintIrestype;6 intiversion;7Unsigned ShortUswidth;8Unsigned ShortUsheight;9Unsigned ShortUsmipmaps;TenUnsigned Shortussections; One intiflags; A intiuserflags; -UnsignedCharubextra[ A]; - Charszcommandstring[ -]; the }; - - #pragmaPack ()
1 BOOLLOADDTX (Const Char*pszfilename, unsignedChar*pbuffer,intIbuffersize,int*pinternalformat,int*pwidth,int*pheight,int*pimagesize)2 {3filehandle_t pFile = G_pfilesystem->open (pszFileName,"RB");4 5 if(!pFile)6 return false;7 8 Dtxheader Header;9memset (&header,0,sizeof(Header));Ten OneG_pfilesystem->read (&header,sizeof(Header), pFile); A - if(Header.irestype! =0|| Header.iversion! =-5|| Header.usmipmaps = =0) - { theG_pfilesystem->Close (pFile); - return false; - } - +*pwidth =Header.uswidth; -*pheight =Header.usheight; + A intIBPP = header.ubextra[2]; at intisize; - - if(IBPP = =0|| IBPP = =3) - { -Isize = header.uswidth * Header.usheight *4; -*pinternalformat =Gl_rgba; in } - Else if(IBPP = =4) to { +Isize = (Header.uswidth * header.usheight) >>1; -*pinternalformat =Gl_compressed_rgba_s3tc_dxt1_ext; the } * Else if(IBPP = =5) $ {Panax NotoginsengIsize = Header.uswidth *Header.usheight; -*pinternalformat =Gl_compressed_rgba_s3tc_dxt3_ext; the } + Else if(IBPP = =6) A { theIsize = Header.uswidth *Header.usheight; +*pinternalformat =Gl_compressed_rgba_s3tc_dxt5_ext; - } $ Else $ { -Isize =0; - } the -*pimagesize =isize;Wuyi the if(Isize = =0|| Isize >ibuffersize) - { WuG_pfilesystem->Close (pFile); - return false; About } $ -G_pfilesystem->Read (pbuffer, Isize, pFile); - - if(IBPP = =3) A { + for(unsignedinti =0; i < isize; i + =4) the { -Pbuffer[i +0] ^= Pbuffer[i +2]; $Pbuffer[i +2] ^= Pbuffer[i +0]; thePbuffer[i +0] ^= Pbuffer[i +2]; the } the } the -G_pfilesystem->Close (pFile); in return true; the}
[Metahook] Load DTX Texture to OpenGL