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; }
CBMP(const char* bmpName) { LoadFileBMP( bmpName, &byte, &m_iWid, &m_iHgh, true); m_iSize = m_iWid*m_iHgh*4; }