7 extern TGAImageRec texture;
13 static vector<TextureRes*> list;
27 TextureRes(const string& filename, bool hasMipmap, bool hasAlpha);
28 TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize);
32 static void reloadAll();
36 vector<TextureRes*> TextureRes::list;
38 void TextureRes::load(){
39 //load image into 'texture' global var
40 unsigned char filenamep[256];
41 CopyCStringToPascal(ConvertFileName(filename.c_str()),filenamep);
42 upload_image(filenamep,hasAlpha);
44 skinsize=texture.sizeX;
49 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
51 glDeleteTextures(1,&id);
53 glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
55 glBindTexture(GL_TEXTURE_2D, id);
56 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
58 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,(trilinear?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR_MIPMAP_NEAREST));
59 glTexParameteri(GL_TEXTURE_2D,GL_GENERATE_MIPMAP,GL_TRUE);
61 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
66 const int nb=texture.sizeY*texture.sizeX*(texture.bpp/8);
67 data=(GLubyte*)malloc(nb*sizeof(GLubyte));
70 if((i+1)%4||type==GL_RGB)
71 data[datalen++]=texture.data[i];
72 glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
74 glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, type, GL_UNSIGNED_BYTE, texture.data);
78 void TextureRes::bind(){
79 glBindTexture(GL_TEXTURE_2D,id);
82 TextureRes::TextureRes(const string& _filename, bool _hasMipmap, bool _hasAlpha):
83 id(0),filename(_filename),hasMipmap(_hasMipmap),hasAlpha(_hasAlpha),isSkin(false),
84 skinsize(0),data(NULL),datalen(0) {
89 TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array, int* skinsizep):
90 id(0),filename(_filename),hasMipmap(_hasMipmap),hasAlpha(false),isSkin(true),
91 skinsize(0),data(NULL),datalen(0) {
94 for(int i=0;i<datalen;i++)
99 TextureRes::~TextureRes(){
101 glDeleteTextures(1,&id);
102 for(vector<TextureRes*>::iterator it=list.begin();it!=list.end();it++)
109 void TextureRes::reloadAll(){
110 for(vector<TextureRes*>::iterator it=list.begin();it!=list.end();it++)
117 void Texture::load(const string& filename, bool hasMipmap, bool hasAlpha){
119 tex=new TextureRes(filename,hasMipmap,hasAlpha);
122 void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep){
124 tex=new TextureRes(filename,hasMipmap,array,skinsizep);
127 void Texture::destroy(){
134 void Texture::bind(){
138 glBindTexture(GL_TEXTURE_2D,0);
141 void Texture::reloadAll(){
142 TextureRes::reloadAll();