TextureLoader::TextureLoader() { // load in the Quake 2 colour palette // WAL textures do not contain definitive colours in RGB format. // Instead, they contain indices into this colour palette, which in turn // has the colours in RGB format. LoadFilePCX( "Q2/pics/colormap.pcx", &palette, NULL, NULL, false ); megaTexture = NULL; };
unsigned int CTextureManager::LoadTexture( const char *filename ) { unsigned int id = 0; unsigned char *texels = 0; int width, height; int success; for( TListItor itor = m_texlist.begin(); itor != m_texlist.end(); ++itor ) { if( strcmp( (*itor)->GetName(), filename ) == 0 ) return (*itor)->GetTexId(); } if( strstr( filename, ".bmp" ) || strstr( filename, ".BMP" ) ) success = LoadFileBMP( filename, &texels, &width, &height, true ); if( strstr( filename, ".tga" ) || strstr( filename, ".TGA" ) ) success = LoadFileTGA( filename, &texels, &width, &height, true ); if( strstr( filename, ".pcx" ) || strstr( filename, ".PCX" ) ) success = LoadFilePCX( filename, &texels, &width, &height, true ); if( success > 0 ) { // create and initialize new texture glGenTextures( 1, &id ); glBindTexture( GL_TEXTURE_2D, id ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, texels ); // create a new CTexture object and push it at the end of the linked list CTexture *tex = new CTexture( id, filename ); m_texlist.push_back( tex ); } else { // can't load the texture, use default texture id = (*m_texlist.begin())->GetTexId(); } if( texels ) delete [] texels; return id; }
/* *************************************************************** * * Takes in a filename that is either a bmp file or a PCX file * and uses the correct loader for the particular filetype. * *************************************************************** */ GLuint TextureManager::loadTextureFromFile(const QString& fileName) { GLuint texture; glGenTextures(1, &texture); glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR); // Linear Filtering glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering glTexParameteri (GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); glHint (GL_GENERATE_MIPMAP_HINT_SGIS, GL_NICEST); int loadSuccessful = 0; if(fileName.contains(QString("bmp"), Qt::CaseInsensitive)) { loadSuccessful = bmpImageReader_.Load(fileName.toAscii().data()); if(loadSuccessful == IMG_OK) { gluBuild2DMipmaps(GL_TEXTURE_2D, 3, bmpImageReader_.GetWidth(), bmpImageReader_.GetHeight() , GL_BGR, GL_UNSIGNED_BYTE, bmpImageReader_.GetImg() ); } } else if(fileName.contains(QString("pcx"), Qt::CaseInsensitive)) { unsigned char* pixels = NULL; pixels = new unsigned char[1]; int width = 0; int height = 0; bool flip = true; loadSuccessful = LoadFilePCX(fileName.toAscii().data(), &pixels, &width, &height, flip); if(1 == loadSuccessful) { gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); } } return texture; }