Advertisement
Guest User

Untitled

a guest
Oct 7th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha)
  2. {
  3.     GLuint      type;
  4.  
  5.     LOGFUNC;
  6.  
  7.     LOG(std::string("Loading texture...") + fileName);
  8.  
  9.     // Fix filename so that is os appropreate
  10.     char * fixedFN = ConvertFileName(fileName);
  11.  
  12.     unsigned char fileNamep[256];
  13.     CopyCStringToPascal(fixedFN, fileNamep);
  14.     //Load Image
  15.     upload_image( fileNamep ,hasalpha);
  16.  
  17.     std::string fname(fileName);
  18.     std::transform(fname.begin(), fname.end(), fname.begin(), ::tolower);
  19.     TexIter it = textures.find(fname);
  20.  
  21.     //Is it valid?
  22.     if(textures.end() == it)
  23.     {
  24.         //Alpha channel?
  25.         if ( texture.bpp == 24 )
  26.             type = GL_RGB;
  27.         else
  28.             type = GL_RGBA;
  29.  
  30.         glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
  31.  
  32.         if(!*textureid)glGenTextures( 1, textureid );
  33.         glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
  34.  
  35.         glBindTexture( GL_TEXTURE_2D, *textureid);
  36.         glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  37.         if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
  38.         if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
  39.         if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  40.  
  41.         glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0,
  42.                   type, GL_UNSIGNED_BYTE, texture.data);
  43.  
  44.         //senquack - Disabled this, and main menu crashes went away
  45. //      gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
  46.  
  47.         textures.insert(std::make_pair(fname, *textureid));
  48.     }
  49.     else
  50.     {
  51.         *textureid = it->second;
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement