Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
- {
- GLuint type;
- LOGFUNC;
- LOG(std::string("Loading texture...") + fileName);
- // Fix filename so that is os appropreate
- char * fixedFN = ConvertFileName(fileName);
- unsigned char fileNamep[256];
- CopyCStringToPascal(fixedFN, fileNamep);
- //Load Image
- upload_image( fileNamep ,hasalpha);
- std::string fname(fileName);
- std::transform(fname.begin(), fname.end(), fname.begin(), ::tolower);
- TexIter it = textures.find(fname);
- //Is it valid?
- if(textures.end() == it)
- {
- //Alpha channel?
- if ( texture.bpp == 24 )
- type = GL_RGB;
- else
- type = GL_RGBA;
- glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
- if(!*textureid)glGenTextures( 1, textureid );
- glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
- glBindTexture( GL_TEXTURE_2D, *textureid);
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
- if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
- if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0,
- type, GL_UNSIGNED_BYTE, texture.data);
- //senquack - Disabled this, and main menu crashes went away
- // gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
- textures.insert(std::make_pair(fname, *textureid));
- }
- else
- {
- *textureid = it->second;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement