/* ============================================================================= =============================================================================== */ int C3DSceneMgr::createTexture(string strFileName, int &width, int &height, int iTxMode) { if (strFileName == "") // Return from the function if no file name was passed in return -1; if (!fileexists(strFileName)) return -1; // Load the image and store the data int textureID = -1; if (getExt(strFileName) == ".dds") { DDS_IMAGE_DATA *pDDSImageData = NULL; if ((pDDSImageData = loadDDSTextureFile(strFileName)) != NULL) { textureID = createTextureDDS(pDDSImageData); height = pDDSImageData->sizeY; width = pDDSImageData->sizeX; } else // case where worldwind wraps jpegs in dds files { Fl_RGB_Image *img = new Fl_JPEG_Image(strFileName.c_str()); if (img->d() == 0) return -1; width = img->w(); height = img->h(); const unsigned char *pData = (const unsigned char *) img->data()[0]; textureID = createTexture(pData, width, height, GL_RGB, GL_RGB, iTxMode); delete img; } } else { Fl_Image * img = openTextureFile(strFileName); if (img == NULL) return -1; width = img->w(); height = img->h(); const unsigned char *pData = (const unsigned char *) img->data()[0]; textureID = createTexture(pData, width, height, img->d() == 4 ? GL_RGBA : GL_RGB, GL_RGBA, iTxMode); delete img; } return textureID; }
//----------------------------------------------------------------------------- // Name: loadCompressedTexture() // Desc: //----------------------------------------------------------------------------- unsigned int CDDS::loadCompressedTexture( const char *filename ,GLint TexParameter) { // NOTE: Unlike "lena.bmp", "lena.dds" actually contains its own mip-map // levels, which are also compressed. g_compressedTextureID=0; DDS_IMAGE_DATA *pDDSImageData = loadDDSTextureFile( filename ); if( pDDSImageData != NULL ) { int nHeight = pDDSImageData->height; int nWidth = pDDSImageData->width; int nNumMipMaps = pDDSImageData->numMipMaps; int nBlockSize; if( pDDSImageData->format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ) nBlockSize = 8; else nBlockSize = 16; glGenTextures( 1, &g_compressedTextureID ); glBindTexture( GL_TEXTURE_2D, g_compressedTextureID ); if(TexParameter!=0) { glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexParameter ); } else { if(nNumMipMaps>1) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); else glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); } glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); int nSize; int nOffset = 0; // Load the mip-map levels for( int i = 0; i < nNumMipMaps; ++i ) { if( nWidth == 0 ) nWidth = 1; if( nHeight == 0 ) nHeight = 1; nSize = ((nWidth+3)/4) * ((nHeight+3)/4) * nBlockSize; glCompressedTexImage2DARB( GL_TEXTURE_2D, i, pDDSImageData->format, nWidth, nHeight, 0, nSize, pDDSImageData->pixels + nOffset ); nOffset += nSize; // Half the image size for the next mip-map level... nWidth = (nWidth / 2); nHeight = (nHeight / 2); } } if( pDDSImageData != NULL ) { if( pDDSImageData->pixels != NULL ) free( pDDSImageData->pixels ); free( pDDSImageData ); } return g_compressedTextureID; }