7 map<string,Texture> Texture::textures;
9 extern TGAImageRec texture;
10 extern bool trilinear;
15 glDeleteTextures(1,&id);
18 void Texture::load() {
23 LOG(std::string("Loading texture...") + fileName);
25 unsigned char fileNamep[256];
26 CopyCStringToPascal(ConvertFileName(fileName.c_str()), fileNamep);
28 upload_image( fileNamep ,hasalpha);
31 if ( texture.bpp == 24 )
36 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
39 glGenTextures( 1, &id );
40 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
42 glBindTexture( GL_TEXTURE_2D, id);
43 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
45 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (trilinear?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR_MIPMAP_NEAREST) );
47 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
49 skinsize=texture.sizeX;
53 int nb = (texture.sizeY*texture.sizeX*(texture.bpp/8));
54 array = (GLubyte*)malloc(nb*sizeof(GLubyte));
55 for(int i=0;i<nb;i++) {
56 if((i+1)%4||type==GL_RGB) {
57 array[tempnum]=texture.data[i];
63 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
65 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
69 GLuint Texture::Load(const string& fileName, bool mipmap, bool hasalpha) {
70 map<string,Texture>::iterator it = textures.find(fileName);
71 if(it==textures.end()) {
72 textures.insert(make_pair(fileName,Texture(fileName,mipmap,hasalpha)));
73 textures[fileName].load();
74 return textures[fileName].getId();
76 return it->second.getId();
80 GLuint Texture::Load(const string& fileName, bool mipmap, bool hasalpha, GLubyte* array, int* skinsize) {
81 map<string,Texture>::iterator it = textures.find(fileName);
82 if(it==textures.end()) {
83 textures.insert(make_pair(fileName,Texture(fileName,mipmap,hasalpha,true)));
84 textures[fileName].load();
85 *skinsize = textures[fileName].skinsize;
86 for(int i=0;i<textures[fileName].arraySize;i++) {
87 array[i] = textures[fileName].array[i];
89 return textures[fileName].getId();
91 *skinsize = it->second.skinsize;
92 for(int i=0;i<it->second.arraySize;i++) {
93 array[i] = it->second.array[i];
95 return it->second.getId();