7 map<string,Texture> Texture::textures;
9 extern TGAImageRec texture;
10 extern bool trilinear;
12 void Texture::load() {
17 LOG(std::string("Loading texture...") + fileName);
19 unsigned char fileNamep[256];
20 CopyCStringToPascal(ConvertFileName(fileName.c_str()), fileNamep);
22 upload_image( fileNamep ,hasalpha);
25 if ( texture.bpp == 24 )
30 glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
33 glGenTextures( 1, &id );
34 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
36 glBindTexture( GL_TEXTURE_2D, id);
37 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
39 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (trilinear?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR_MIPMAP_NEAREST) );
41 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
43 skinsize=texture.sizeX;
47 int nb = (texture.sizeY*texture.sizeX*(texture.bpp/8));
48 array = (GLubyte*)malloc(nb*sizeof(GLubyte));
49 for(int i=0;i<nb;i++) {
50 if((i+1)%4||type==GL_RGB) {
51 array[tempnum]=texture.data[i];
57 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
59 gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
63 GLuint Texture::Load(const string& fileName, bool mipmap, bool hasalpha) {
64 map<string,Texture>::iterator it = textures.find(fileName);
65 if(it==textures.end()) {
66 textures.insert(make_pair(fileName,Texture(fileName,mipmap,hasalpha)));
67 textures[fileName].load();
68 return textures[fileName].getId();
70 return it->second.getId();
74 GLuint Texture::Load(const string& fileName, bool mipmap, bool hasalpha, GLubyte* array, int* skinsize) {
75 map<string,Texture>::iterator it = textures.find(fileName);
76 if(it==textures.end()) {
77 textures.insert(make_pair(fileName,Texture(fileName,mipmap,hasalpha,true)));
78 textures[fileName].load();
79 *skinsize = textures[fileName].skinsize;
80 for(int i=0;i<textures[fileName].arraySize;i++) {
81 array[i] = textures[fileName].array[i];
83 return textures[fileName].getId();
85 *skinsize = it->second.skinsize;
86 for(int i=0;i<it->second.arraySize;i++) {
87 array[i] = it->second.array[i];
89 return it->second.getId();