X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;ds=sidebyside;f=Source%2FTexture.cpp;h=150eee73b76a0fb00d9a1950d5f838def3a32292;hb=97989f58ab13c64fbe05e629d2b2a024a2c3cfa4;hp=ef20536da7b37f7268607d0a52ba0e44df69569e;hpb=801987203c1ae03f2d9592a92d933fdba73854c2;p=lugaru.git
diff --git a/Source/Texture.cpp b/Source/Texture.cpp
index ef20536..150eee7 100644
--- a/Source/Texture.cpp
+++ b/Source/Texture.cpp
@@ -1,14 +1,34 @@
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+Lugaru is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Lugaru. If not, see .
+*/
+
#include "gamegl.h"
#include "Texture.h"
-#include "TGALoader.h"
+#include "ImageIO.h"
using namespace std;
-extern TGAImageRec texture;
+extern ImageRec texture;
extern bool trilinear;
-class TextureRes {
+class TextureRes
+{
private:
static vector list;
@@ -36,119 +56,126 @@ public:
vector TextureRes::list;
-void TextureRes::load(){
+void TextureRes::load()
+{
//load image into 'texture' global var
- if(!skindata){
- unsigned char filenamep[256];
- CopyCStringToPascal(ConvertFileName(filename.c_str()),filenamep);
- upload_image(filenamep,hasAlpha);
+ if (!skindata) {
+ upload_image(ConvertFileName(filename.c_str()));
}
-
- 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);
+
+ 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){
- if(skindata){
+
+ if (isSkin) {
+ if (skindata) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skinsize, skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, skindata);
- }else{
+ } else {
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::iterator it=list.begin();it!=list.end();it++)
- if(*it==this){
+ glDeleteTextures(1, &id);
+ for (vector::iterator it = list.begin(); it != list.end(); it++)
+ if (*it == this) {
list.erase(it);
break;
}
}
-void TextureRes::reloadAll(){
- for(vector::iterator it=list.begin();it!=list.end();it++){
- (*it)->id=0;
+void TextureRes::reloadAll()
+{
+ for (vector::iterator it = list.begin(); it != list.end(); it++) {
+ (*it)->id = 0;
(*it)->load();
}
}
-
-
-void Texture::load(const string& filename, bool hasMipmap, bool hasAlpha){
+void Texture::load(const string& filename, bool hasMipmap, bool hasAlpha)
+{
destroy();
- tex=new TextureRes(filename,hasMipmap,hasAlpha);
+ tex = new TextureRes(filename, hasMipmap, hasAlpha);
}
-void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep){
+void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep)
+{
destroy();
- tex=new TextureRes(filename,hasMipmap,array,skinsizep);
+ tex = new TextureRes(filename, hasMipmap, array, skinsizep);
}
-void Texture::destroy(){
- if(tex){
+void Texture::destroy()
+{
+ if (tex) {
delete tex;
- tex=NULL;
+ tex = NULL;
}
}
-void Texture::bind(){
- if(tex)
+void Texture::bind()
+{
+ if (tex)
tex->bind();
else
- glBindTexture(GL_TEXTURE_2D,0);
+ glBindTexture(GL_TEXTURE_2D, 0);
}
-void Texture::reloadAll(){
+void Texture::reloadAll()
+{
TextureRes::reloadAll();
}