+vector<TextureRes*> TextureRes::list;
+
+void TextureRes::load()
+{
+ ImageRec texture;
+
+ //load image into 'texture'
+ if (!load_image(filename.c_str(), texture)) {
+ cerr << "Texture " << filename << " loading failed" << endl;
+ return;
+ }
+
+ skinsize = texture.sizeX;
+ GLuint type = GL_RGBA;
+ if (texture.bpp == 24)
+ type = GL_RGB;
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ glDeleteTextures(1, &id);
+ glGenTextures(1, &id);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+ glBindTexture(GL_TEXTURE_2D, id);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ if (hasMipmap) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (trilinear ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR_MIPMAP_NEAREST));
+ glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
+ } else {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ }
+
+ if (isSkin) {
+ free(data);
+ const int nb = texture.sizeY * texture.sizeX * (texture.bpp / 8);
+ data = (GLubyte*)malloc(nb * sizeof(GLubyte));
+ datalen = 0;
+ for (int i = 0; i < nb; i++)
+ if ((i + 1) % 4 || type == GL_RGB)
+ data[datalen++] = texture.data[i];
+ glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
+ } else {
+ glTexImage2D(GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, type, GL_UNSIGNED_BYTE, texture.data);
+ }
+}
+
+void TextureRes::bind()
+{
+ glBindTexture(GL_TEXTURE_2D, id);
+}
+
+TextureRes::TextureRes(const string& _filename, bool _hasMipmap):
+ id(0), filename(_filename), hasMipmap(_hasMipmap), isSkin(false),
+ skinsize(0), data(NULL), datalen(0)
+{
+ load();
+ list.push_back(this);