7 extern TGAImageRec texture;
13 static vector<TextureRes*> list;
28 TextureRes(const string& filename, bool hasMipmap, bool hasAlpha);
29 TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize);
33 static void reloadAll();
37 vector<TextureRes*> TextureRes::list;
39 void TextureRes::load(){
40 //load image into 'texture' global var
42 unsigned char filenamep[256];
43 CopyCStringToPascal(ConvertFileName(filename.c_str()),filenamep);
44 upload_image(filenamep,hasAlpha);
47 skinsize=texture.sizeX;
52 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
54 glDeleteTextures(1,&id);
56 glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
58 glBindTexture(GL_TEXTURE_2D, id);
59 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
61 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,(trilinear?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR_MIPMAP_NEAREST));
62 glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_TRUE);
64 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
69 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skinsize, skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, skindata);
72 const int nb=texture.sizeY*texture.sizeX*(texture.bpp/8);
73 data=(GLubyte*)malloc(nb*sizeof(GLubyte));
76 if((i+1)%4||type==GL_RGB)
77 data[datalen++]=texture.data[i];
78 glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
81 glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, type, GL_UNSIGNED_BYTE, texture.data);
85 void TextureRes::bind(){
86 glBindTexture(GL_TEXTURE_2D,id);
89 TextureRes::TextureRes(const string& _filename, bool _hasMipmap, bool _hasAlpha):
90 id(0),filename(_filename),hasMipmap(_hasMipmap),hasAlpha(_hasAlpha),isSkin(false),
91 skinsize(0),data(NULL),datalen(0),skindata(NULL) {
96 TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array, int* skinsizep):
97 id(0),filename(_filename),hasMipmap(_hasMipmap),hasAlpha(false),isSkin(true),
98 skinsize(0),data(NULL),datalen(0),skindata(NULL) {
101 for(int i=0;i<datalen;i++)
104 list.push_back(this);
107 TextureRes::~TextureRes(){
109 glDeleteTextures(1,&id);
110 for(vector<TextureRes*>::iterator it=list.begin();it!=list.end();it++)
117 void TextureRes::reloadAll(){
118 for(vector<TextureRes*>::iterator it=list.begin();it!=list.end();it++){
127 void Texture::load(const string& filename, bool hasMipmap, bool hasAlpha){
129 tex=new TextureRes(filename,hasMipmap,hasAlpha);
132 void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep){
134 tex=new TextureRes(filename,hasMipmap,array,skinsizep);
137 void Texture::destroy(){
144 void Texture::bind(){
148 glBindTexture(GL_TEXTURE_2D,0);
151 void Texture::reloadAll(){
152 TextureRes::reloadAll();