]> git.jsancho.org Git - lugaru.git/commitdiff
major refactor of texture system
authorsf17k <sf171k@gmail.com>
Wed, 8 Jun 2011 12:51:45 +0000 (08:51 -0400)
committersf17k <sf171k@gmail.com>
Wed, 8 Jun 2011 12:51:45 +0000 (08:51 -0400)
25 files changed:
Source/Game.cpp
Source/Game.h
Source/GameDraw.cpp
Source/GameInitDispose.cpp
Source/GameTick.cpp
Source/Menu.cpp
Source/Menu.h
Source/Models.cpp
Source/Models.h
Source/Objects.cpp
Source/Objects.h
Source/Person.cpp
Source/Person.h
Source/Skybox.cpp
Source/Skybox.h
Source/Sprite.cpp
Source/Sprite.h
Source/Terrain.cpp
Source/Terrain.h
Source/Text.cpp
Source/Text.h
Source/Texture.cpp
Source/Texture.h
Source/Weapons.cpp
Source/Weapons.h

index 2beac5a342b9d21beff4582ae6b9318a3fdebab2..debf51a872ea7cf40714da3f7967b693593e4253 100644 (file)
@@ -27,18 +27,16 @@ float dialoguetime;
 int dialoguegonethrough[20];
 
 namespace Game{
-    GLuint terraintexture = 0;
-    GLuint terraintexture2 = 0;
-    GLuint terraintexture3 = 0;
+    Texture terraintexture;
+    Texture terraintexture2;
+    Texture loadscreentexture;
+    Texture Maparrowtexture;
+    Texture Mapboxtexture;
+    Texture Mapcircletexture;
+    Texture cursortexture;
     GLuint screentexture = 0;
     GLuint screentexture2 = 0;
-    GLuint logotexture = 0;
-    GLuint loadscreentexture = 0;
-    GLuint Maparrowtexture = 0;
-    GLuint Mapboxtexture = 0;
-    GLuint Mapcircletexture = 0;
-    GLuint cursortexture = 0;
-    GLuint Mainmenuitems[10] = {};
+    Texture Mainmenuitems[10];
 
     int selected = 0;
     int keyselect = 0;
@@ -60,7 +58,7 @@ namespace Game{
     bool cameramode = 0;
     bool firstload = 0;
 
-       GLuint hawktexture = 0;
+       Texture hawktexture;
        float hawkyaw = 0;
        float hawkcalldelay = 0;
     float leveltime = 0;
index ec30c86ae7a00df3267cbe7494830cd63aaa640c..a378efcd28b3fb249a06d6f4c04769ac97ef4f01 100644 (file)
@@ -58,22 +58,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Stereo.h"
 #include "Account.h"
 #include "Sounds.h"
+#include "Texture.h"
 
 #define NB_CAMPAIGN_MENU_ITEM 7
 
 namespace Game {
-    extern GLuint terraintexture;
-    extern GLuint terraintexture2;
-    extern GLuint terraintexture3;
+    extern Texture terraintexture;
+    extern Texture terraintexture2;
+    extern Texture loadscreentexture;
+    extern Texture Maparrowtexture;
+    extern Texture Mapboxtexture;
+    extern Texture Mapcircletexture;
+    extern Texture cursortexture;
     extern GLuint screentexture;
     extern GLuint screentexture2;
-    extern GLuint logotexture;
-    extern GLuint loadscreentexture;
-    extern GLuint Maparrowtexture;
-    extern GLuint Mapboxtexture;
-    extern GLuint Mapcircletexture;
-    extern GLuint cursortexture;
-    extern GLuint Mainmenuitems[10];
+    extern Texture Mainmenuitems[10];
 
     extern int selected;
     extern int keyselect;
@@ -97,7 +96,7 @@ namespace Game {
     extern Model hawk;
     extern XYZ hawkcoords;
     extern XYZ realhawkcoords;
-    extern GLuint hawktexture;
+    extern Texture hawktexture;
     extern float hawkyaw;
     extern float hawkcalldelay;
 
@@ -161,10 +160,9 @@ namespace Game {
     void newGame();
     void deleteGame();
 
-    void LoadTexture(const string fileName, GLuint *textureid,int mipmap, bool hasalpha);
-    void LoadTextureSave(const string fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
     void InitGame();
     void LoadStuff();
+    void LoadScreenTexture();
     void LoadingScreen();
     int DrawGLScene(StereoSide side);
     void LoadMenu();
index 11a94010c5b5ebd1aedce2ed4690b21771498e02..a6b02a5ff748f91cc2d64914da7cc0afcad63713 100644 (file)
@@ -404,9 +404,9 @@ int Game::DrawGLScene(StereoSide side)
                glDisable(GL_BLEND);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
-               glBindTexture( GL_TEXTURE_2D, terraintexture);
+               terraintexture.bind();
                terrain.draw(0);
-               glBindTexture( GL_TEXTURE_2D, terraintexture2);
+               terraintexture2.bind();
                terrain.draw(1);
                //glBindTexture( GL_TEXTURE_2D, terraintexture3);
                //glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@@ -1502,7 +1502,7 @@ int Game::DrawGLScene(StereoSide side)
                                if(objects.type[i]==treetrunktype){
                                        distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
                                        if(distcheck<mapviewdist){
-                                               glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
+                        Mapcircletexture.bind();
                                                glColor4f(0,.3,0,opac*(1-distcheck/mapviewdist));
                                                glPushMatrix();
                                                glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
@@ -1524,7 +1524,7 @@ int Game::DrawGLScene(StereoSide side)
                                if(objects.type[i]==boxtype){
                                        distcheck=findDistancefast(&player[0].coords,&objects.position[i]);
                                        if(distcheck<mapviewdist){
-                                               glBindTexture( GL_TEXTURE_2D, Mapboxtexture);
+                                               Mapboxtexture.bind();
                                                glColor4f(.4,.4,.4,opac*(1-distcheck/mapviewdist));
                                                glPushMatrix();
                                                glTranslatef(objects.position[i].x/terrain.scale/256*-2+1,objects.position[i].z/terrain.scale/256*2-1,0);
@@ -1545,7 +1545,7 @@ int Game::DrawGLScene(StereoSide side)
                                }
                        }
                        if(editorenabled){
-                               glBindTexture( GL_TEXTURE_2D, Mapcircletexture);
+                               Mapcircletexture.bind();
                                for(i=0;i<numboundaries;i++){
                                        glColor4f(0,0,0,opac/3);
                                        glPushMatrix();
@@ -1568,7 +1568,7 @@ int Game::DrawGLScene(StereoSide side)
                                distcheck=findDistancefast(&player[0].coords,&player[i].coords);
                                if(distcheck<mapviewdist){
                                        glPushMatrix();
-                                       glBindTexture( GL_TEXTURE_2D, Maparrowtexture);
+                    Maparrowtexture.bind();
                                        if(i==0)glColor4f(1,1,1,opac);
                                        else if(player[i].dead==2||player[i].howactive>typesleeping)glColor4f(0,0,0,opac*(1-distcheck/mapviewdist));
                                        else if(player[i].dead)glColor4f(.3,.3,.3,opac*(1-distcheck/mapviewdist));
@@ -2078,7 +2078,7 @@ void DrawMenu() {
                                glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
                                glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
                                glEnable(GL_TEXTURE_2D);
-                               glBindTexture( GL_TEXTURE_2D, Game::Mainmenuitems[4]);
+                               Game::Mainmenuitems[4].bind();
                                        glBegin(GL_QUADS);
                                        glTexCoord2f(0,0);
                                        glVertex3f(-1,-1,0);
@@ -2138,7 +2138,7 @@ void DrawMenu() {
                                                glTranslatef(1,-1,0);
                                                glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
                                                glColor4f(1,1,1,1);
-                                               glBindTexture( GL_TEXTURE_2D, Game::cursortexture);
+                        Game::cursortexture.bind();
                                                glPushMatrix();
                                                        //glScalef(.25,.25,.25);
                                                        glBegin(GL_QUADS);
index 8c0917914c4bcb3b9b79d544503292b53f0feefc..24edee3ff98c6db20368ad2cdfa0f9025eb3bc50 100644 (file)
@@ -138,36 +138,28 @@ void Game::newGame(){
 }
 
 void Game::deleteGame(){
-    if(skybox)
-        delete skybox;
-    if(text)
-        delete text;
-    glDeleteTextures( 10, &Mainmenuitems[0] );
-    glDeleteTextures( 1, &cursortexture );
-    glDeleteTextures( 1, &Maparrowtexture );
-    glDeleteTextures( 1, &Mapboxtexture );
-    glDeleteTextures( 1, &Mapcircletexture );
-    glDeleteTextures( 1, &terraintexture );
-    glDeleteTextures( 1, &terraintexture2 );
-    glDeleteTextures( 1, &screentexture );
-    glDeleteTextures( 1, &screentexture2 );
-    glDeleteTextures( 1, &hawktexture );
-    glDeleteTextures( 1, &logotexture );
-    glDeleteTextures( 1, &loadscreentexture );
+    if(skybox) delete skybox;
+    if(text) delete text;
+    terraintexture.destroy();
+    terraintexture2.destroy();
+    cursortexture.destroy();
+    Maparrowtexture.destroy();
+    Mapboxtexture.destroy();
+    Mapcircletexture.destroy();
+    hawktexture.destroy();
+    loadscreentexture.destroy();
+
+    for(int i=0;i<10;i++)
+        Mainmenuitems[i].destroy();
+
+    glDeleteTextures(1,&screentexture);
+    glDeleteTextures(1,&screentexture2);
 
     Dispose();
 }
 
 
 
-void Game::LoadTexture(const string fileName, GLuint *textureid,int mipmap, bool hasalpha) {
-       *textureid = Texture::Load(fileName,mipmap,hasalpha);
-}
-
-void Game::LoadTextureSave(const string fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize) {
-       *textureid = Texture::Load(fileName,mipmap,false,array,skinsize);
-}
-
 void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
 {
        int i;
@@ -263,7 +255,7 @@ void Game::LoadingScreen()
                //Background
 
                glEnable(GL_TEXTURE_2D);
-               glBindTexture( GL_TEXTURE_2D, loadscreentexture);
+        loadscreentexture.bind();
                glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
                glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
                glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
@@ -318,7 +310,7 @@ void Game::LoadingScreen()
                glDepthMask(1);
 
                glEnable(GL_TEXTURE_2D);
-               glBindTexture( GL_TEXTURE_2D, loadscreentexture);
+        loadscreentexture.bind();
                glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
                glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
                glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
@@ -360,7 +352,7 @@ void Game::LoadingScreen()
                glDepthMask(1);
 
                glEnable(GL_TEXTURE_2D);
-               glBindTexture( GL_TEXTURE_2D, loadscreentexture);
+        loadscreentexture.bind();
                glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
                glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
                glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
@@ -681,21 +673,21 @@ void Game::InitGame()
        if(musictoggle)
          emit_stream_np(stream_menutheme);
 
-       LoadTexture(":Data:Textures:Cursor.png",&cursortexture,0,1);
+       cursortexture.load(":Data:Textures:Cursor.png",0,1);
 
-       LoadTexture(":Data:Textures:MapCircle.png",&Mapcircletexture,0,1);
-       LoadTexture(":Data:Textures:MapBox.png",&Mapboxtexture,0,1);
-       LoadTexture(":Data:Textures:MapArrow.png",&Maparrowtexture,0,1);
+       Mapcircletexture.load(":Data:Textures:MapCircle.png",0,1);
+       Mapboxtexture.load(":Data:Textures:MapBox.png",0,1);
+       Maparrowtexture.load(":Data:Textures:MapArrow.png",0,1);
 
        temptexdetail=texdetail;
        if(texdetail>2)texdetail=2;
-       LoadTexture(":Data:Textures:Lugaru.png",&Mainmenuitems[0],0,0);
-       LoadTexture(":Data:Textures:Newgame.png",&Mainmenuitems[1],0,0);
-       LoadTexture(":Data:Textures:Options.png",&Mainmenuitems[2],0,0);
-       LoadTexture(":Data:Textures:Quit.png",&Mainmenuitems[3],0,0);
-       LoadTexture(":Data:Textures:Eyelid.png",&Mainmenuitems[4],0,1);
-       LoadTexture(":Data:Textures:Resume.png",&Mainmenuitems[5],0,0);
-       LoadTexture(":Data:Textures:Endgame.png",&Mainmenuitems[6],0,0);
+       Mainmenuitems[0].load(":Data:Textures:Lugaru.png",0,0);
+       Mainmenuitems[1].load(":Data:Textures:Newgame.png",0,0);
+       Mainmenuitems[2].load(":Data:Textures:Options.png",0,0);
+       Mainmenuitems[3].load(":Data:Textures:Quit.png",0,0);
+       Mainmenuitems[4].load(":Data:Textures:Eyelid.png",0,1);
+       Mainmenuitems[5].load(":Data:Textures:Resume.png",0,0);
+       Mainmenuitems[6].load(":Data:Textures:Endgame.png",0,0);
        
        //LoadTexture(":Data:Textures:Eye.jpg",&Mainmenuitems[5],0,1);
        //~ LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0); // LoadCampaign will take care of that
@@ -718,7 +710,7 @@ void Game::InitGame()
 }
 
 
-void LoadScreenTexture() {
+void Game::LoadScreenTexture() {
     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
 
     if(!Game::screentexture)
@@ -744,20 +736,17 @@ void Game::LoadStuff()
 
        LOGFUNC;
 
-       visibleloading=1;
-
        loadtime=0;
 
        stillloading=1;
 
        for(i=0;i<maxplayers;i++)
-       {
-        glDeleteTextures(1, &player[i].skeleton.drawmodel.textureptr);
-               player[i].skeleton.drawmodel.textureptr=0;;
-       }
+               player[i].skeleton.drawmodel.textureptr.destroy();
 
        i=abs(Random()%4);
-       LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
+       visibleloading=0; //don't use loadscreentexture yet
+       loadscreentexture.load(":Data:Textures:fire.jpg",1,0);
+       visibleloading=1;
 
        temptexdetail=texdetail;
        texdetail=1;
@@ -787,13 +776,13 @@ void Game::LoadStuff()
 
        LOG("Loading weapon data...");
 
-       LoadTexture(":Data:Textures:knife.png",&Weapon::knifetextureptr,0,1);
-       LoadTexture(":Data:Textures:bloodknife.png",&Weapon::bloodknifetextureptr,0,1);
-       LoadTexture(":Data:Textures:lightbloodknife.png",&Weapon::lightbloodknifetextureptr,0,1);
-       LoadTexture(":Data:Textures:sword.jpg",&Weapon::swordtextureptr,1,0);
-       LoadTexture(":Data:Textures:Swordblood.jpg",&Weapon::bloodswordtextureptr,1,0);
-       LoadTexture(":Data:Textures:Swordbloodlight.jpg",&Weapon::lightbloodswordtextureptr,1,0);
-       LoadTexture(":Data:Textures:Staff.jpg",&Weapon::stafftextureptr,1,0);
+       Weapon::knifetextureptr.load(":Data:Textures:knife.png",0,1);
+       Weapon::bloodknifetextureptr.load(":Data:Textures:bloodknife.png",0,1);
+       Weapon::lightbloodknifetextureptr.load(":Data:Textures:lightbloodknife.png",0,1);
+       Weapon::swordtextureptr.load(":Data:Textures:sword.jpg",1,0);
+       Weapon::bloodswordtextureptr.load(":Data:Textures:Swordblood.jpg",1,0);
+       Weapon::lightbloodswordtextureptr.load(":Data:Textures:Swordbloodlight.jpg",1,0);
+       Weapon::stafftextureptr.load(":Data:Textures:Staff.jpg",1,0);
 
        Weapon::throwingknifemodel.load((char *)":Data:Models:throwingknife.solid",1);
        Weapon::throwingknifemodel.Scale(.001,.001,.001);
@@ -824,35 +813,28 @@ void Game::LoadStuff()
        Weapon::staffmodel.CalculateNormals(1);
        //Weapon::staffmodel.ScaleNormals(-1,-1,-1);
 
-       LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
-
-       LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
-
-       LoadTexture(":Data:Textures:break.png",&terrain.breaktexture,0,1);
-
-       LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture2,0,1);
-
-
-       LoadTexture(":Data:Textures:footprint.png",&terrain.footprinttexture,0,1);
-
-       LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
+       terrain.shadowtexture.load(":Data:Textures:shadow.png",0,1);
+       terrain.bloodtexture.load(":Data:Textures:blood.png",0,1);
+       terrain.breaktexture.load(":Data:Textures:break.png",0,1);
+       terrain.bloodtexture2.load(":Data:Textures:blood.png",0,1);
 
-       LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
 
-       LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
+       terrain.footprinttexture.load(":Data:Textures:footprint.png",0,1);
+       terrain.bodyprinttexture.load(":Data:Textures:bodyprint.png",0,1);
+       hawktexture.load(":Data:Textures:hawk.png",0,1);
 
 
-       LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
-       LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
-       LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
-       LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1,1);
-       LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1,1);
-       LoadTexture(":Data:Textures:bloodflame.png",&Sprite::bloodflametexture,1,1);
-       LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1,1);
-       LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1,0);
-       LoadTexture(":Data:Textures:splinter.png",&Sprite::splintertexture,1,1);
-       LoadTexture(":Data:Textures:leaf.png",&Sprite::leaftexture,1,1);
-       LoadTexture(":Data:Textures:tooth.png",&Sprite::toothtexture,1,1);
+       Sprite::cloudtexture.load(":Data:Textures:cloud.png",1,1);
+       Sprite::cloudimpacttexture.load(":Data:Textures:cloudimpact.png",1,1);
+       Sprite::bloodtexture.load(":Data:Textures:bloodparticle.png",1,1);
+       Sprite::snowflaketexture.load(":Data:Textures:snowflake.png",1,1);
+       Sprite::flametexture.load(":Data:Textures:flame.png",1,1);
+       Sprite::bloodflametexture.load(":Data:Textures:bloodflame.png",1,1);
+       Sprite::smoketexture.load(":Data:Textures:smoke.png",1,1);
+       Sprite::shinetexture.load(":Data:Textures:shine.png",1,0);
+       Sprite::splintertexture.load(":Data:Textures:splinter.png",1,1);
+       Sprite::leaftexture.load(":Data:Textures:leaf.png",1,1);
+       Sprite::toothtexture.load(":Data:Textures:tooth.png",1,1);
 
        yaw=0;
        pitch=0;
index 99dab372a90a5850442ae0b97b3706401a20522e..baac306c54fa82ac7bcd59d5ca05bf847897cd11 100644 (file)
@@ -566,7 +566,7 @@ static void ch_save(const char *args){
 
 static void ch_cellar(const char *args)
 {
-  LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:Furdarko.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
 static void ch_tint(const char *args)
@@ -733,9 +733,9 @@ static void ch_metal(const char *args)
 static void set_noclothes(int pnum, const char *args)
 {
   player[pnum].numclothes = 0;
-  LoadTextureSave(creatureskin[player[pnum].creature][player[pnum].whichskin],
-                       &player[pnum].skeleton.drawmodel.textureptr,1,
-                       &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
+  player[pnum].skeleton.drawmodel.textureptr.load(
+          creatureskin[player[pnum].creature][player[pnum].whichskin],1,
+          &player[pnum].skeleton.skinText[0],&player[pnum].skeleton.skinsize);
 }
 
 static void ch_noclothes(const char *args)
@@ -807,8 +807,7 @@ static void ch_funnybunny(const char *args)
                          ":Data:Models:Body4.solid",":Data:Models:Body5.solid",
                          ":Data:Models:Body6.solid",":Data:Models:Body7.solid",
                          ":Data:Models:Bodylow.solid",":Data:Models:Belt.solid",1);
-  LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:fur3.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   player[0].creature=rabbittype;
   player[0].scale=.2;
   player[0].headless=0;
@@ -825,8 +824,7 @@ static void ch_wolfie(const char *args)
                          ":Data:Models:Wolf4.solid",":Data:Models:Wolf5.solid",
                          ":Data:Models:Wolf6.solid",":Data:Models:Wolf7.solid",
                          ":Data:Models:Wolflow.solid",":Data:Models:Belt.solid",0);
-  LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
   player[0].creature=wolftype;
   player[0].damagetolerance=300;
   set_proportion(0, "1 1 1 1");
@@ -839,44 +837,37 @@ static void ch_wolfieisgod(const char *args)
 
 static void ch_wolf(const char *args)
 {
-  LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
 static void ch_snowwolf(const char *args)
 {
-  LoadTextureSave(":Data:Textures:SnowWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:SnowWolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
 static void ch_darkwolf(const char *args)
 {
-  LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:DarkWolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
 static void ch_lizardwolf(const char *args)
 {
-  LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:Lizardwolf.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
 static void ch_white(const char *args)
 {
-  LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:fur.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
 static void ch_brown(const char *args)
 {
-  LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:fur3.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
 static void ch_black(const char *args)
 {
-  LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,
-                       &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(":Data:Textures:fur2.jpg",1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 }
 
 static void ch_sizemin(const char *args)
@@ -1107,9 +1098,9 @@ static void ch_default(const char *args)
   }
 
   player[0].numclothes=0;
-  LoadTextureSave(creatureskin[player[0].creature][player[0].whichskin],
-                       &player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],
-                       &player[0].skeleton.skinsize);
+  player[0].skeleton.drawmodel.textureptr.load(
+          creatureskin[player[0].creature][player[0].whichskin],1,
+          &player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
 
   editoractive=typeactive;
   player[0].immobile=0;
@@ -1400,19 +1391,18 @@ void Setenvironment(int which)
                if(ambientsound)
                  emit_stream_np(stream_wind);
 
-               LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
-               LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
-               LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
-               LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
+               objects.treetextureptr.load(":Data:Textures:snowtree.png",0,1);
+               objects.bushtextureptr.load(":Data:Textures:bushsnow.png",0,1);
+               objects.rocktextureptr.load(":Data:Textures:bouldersnow.jpg",1,0);
+               objects.boxtextureptr.load(":Data:Textures:snowbox.jpg",1,0);
 
                footstepsound = footstepsn1;
                footstepsound2 = footstepsn2;
                footstepsound3 = footstepst1;
                footstepsound4 = footstepst2;
 
-               LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
-
-               LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
+               terraintexture.load(":Data:Textures:snow.jpg",1,0);
+               terraintexture2.load(":Data:Textures:rock.jpg",1,0);
 
                //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
 
@@ -1435,10 +1425,10 @@ void Setenvironment(int which)
        } else if(environment==desertenvironment){
                windvector=0;
                windvector.z=2;
-               LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
-               LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
-               LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
-               LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
+               objects.treetextureptr.load(":Data:Textures:deserttree.png",0,1);
+               objects.bushtextureptr.load(":Data:Textures:bushdesert.png",0,1);
+               objects.rocktextureptr.load(":Data:Textures:boulderdesert.jpg",1,0);
+               objects.boxtextureptr.load(":Data:Textures:desertbox.jpg",1,0);
 
 
                if(ambientsound)
@@ -1449,9 +1439,8 @@ void Setenvironment(int which)
                footstepsound3 = footstepsn1;
                footstepsound4 = footstepsn2;
 
-               LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
-
-               LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
+               terraintexture.load(":Data:Textures:sand.jpg",1,0);
+               terraintexture2.load(":Data:Textures:sandslope.jpg",1,0);
 
                //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
 
@@ -1473,10 +1462,10 @@ void Setenvironment(int which)
        } else if(environment==grassyenvironment){
                windvector=0;
                windvector.z=2;
-               LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
-               LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
-               LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
-               LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
+               objects.treetextureptr.load(":Data:Textures:tree.png",0,1);
+               objects.bushtextureptr.load(":Data:Textures:bush.png",0,1);
+               objects.rocktextureptr.load(":Data:Textures:boulder.jpg",1,0);
+               objects.boxtextureptr.load(":Data:Textures:grassbox.jpg",1,0);
 
                if(ambientsound)
                  emit_stream_np(stream_wind, 100.);
@@ -1486,9 +1475,8 @@ void Setenvironment(int which)
                footstepsound3 = footstepst1;
                footstepsound4 = footstepst2;
 
-               LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
-
-               LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
+               terraintexture.load(":Data:Textures:grassdirt.jpg",1,0);
+               terraintexture2.load(":Data:Textures:mossrock.jpg",1,0);
 
                //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
 
@@ -1531,9 +1519,9 @@ void LoadCampaign() {
 
        ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
        if(test.good()) {
-               LoadTexture((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
+               Mainmenuitems[7].load((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),0,0);
        } else {
-               LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
+               Mainmenuitems[7].load(":Data:Textures:World.png",0,0);
        }
 
        if(accountactive->getCampaignChoicesMade()==0) {
@@ -2076,7 +2064,7 @@ void Loadlevel(const char *name) {
                             (char *)":Data:Models:Body7.solid",
                             (char *)":Data:Models:Bodylow.solid",
                             (char *)":Data:Models:Belt.solid",1);
-                                       LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
+                                       player[i].skeleton.drawmodelclothes.textureptr.load(":Data:Textures:Belt.png",1,1);
                                }
                                if(player[i].creature==wolftype){
                                        player[i].skeleton.Load(
@@ -2099,7 +2087,7 @@ void Loadlevel(const char *name) {
                        //~ int texsize;
                        //~ texsize=512*512*3/texdetail/texdetail;
 
-                       LoadTextureSave(creatureskin[player[i].creature][player[i].whichskin],&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
+                       player[i].skeleton.drawmodel.textureptr.load(creatureskin[player[i].creature][player[i].whichskin],1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
 
                        if(player[i].numclothes){
                                for(int j=0;j<player[i].numclothes;j++){
@@ -2732,8 +2720,8 @@ void doDebugKeys(){
                 if(player[closest].whichskin>2&&player[closest].creature==wolftype)
                     player[closest].whichskin=0;
 
-                LoadTextureSave(creatureskin[player[closest].creature][player[closest].whichskin],
-                        &player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
+                player[closest].skeleton.drawmodel.textureptr.load(creatureskin[player[closest].creature][player[closest].whichskin],1,
+                        &player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
             }
 
             if(player[closest].numclothes){
@@ -2778,7 +2766,7 @@ void doDebugKeys(){
                 if(player[closest].creature==rabbittype){
                     player[closest].skeleton.id=closest;
                     player[closest].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
-                    LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
+                    player[closest].skeleton.drawmodel.textureptr.load(":Data:Textures:Wolf.jpg",1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
                     player[closest].whichskin=0;
                     player[closest].creature=wolftype;
 
@@ -2795,7 +2783,7 @@ void doDebugKeys(){
                 {
                     player[closest].skeleton.id=closest;
                     player[closest].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
-                    LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
+                    player[closest].skeleton.drawmodel.textureptr.load(":Data:Textures:Fur3.jpg",1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
                     player[closest].whichskin=0;
                     player[closest].creature=rabbittype;
 
@@ -3115,19 +3103,19 @@ void doDebugKeys(){
 
                     int k=abs(Random()%2)+1;
                     if(k==0){
-                        LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
+                        player[numplayers].skeleton.drawmodel.textureptr.load(":Data:Textures:Fur3.jpg",1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
                         player[numplayers].whichskin=0;
                     }
                     else if(k==1){
-                        LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
+                        player[numplayers].skeleton.drawmodel.textureptr.load(":Data:Textures:Fur.jpg",1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
                         player[numplayers].whichskin=1;
                     }
                     else {
-                        LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
+                        player[numplayers].skeleton.drawmodel.textureptr.load(":Data:Textures:Fur2.jpg",1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
                         player[numplayers].whichskin=2;
                     }
 
-                    LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
+                    player[numplayers].skeleton.drawmodelclothes.textureptr.load(":Data:Textures:Belt.png",1,1);
                     player[numplayers].power=1;
                     player[numplayers].speedmult=1;
                     player[numplayers].currentanimation=bounceidleanim;
index f6a1957527611a0e4cfc17bfa95163567c73072f..1d8718d5644d40db5846ef91ac9f26dfee862410 100644 (file)
@@ -11,7 +11,7 @@ struct MenuItem {
     enum MenuItemType{NONE,LABEL,BUTTON,IMAGE,IMAGEBUTTON,MAPMARKER,MAPLINE,MAPLABEL} type;
     int id;
     string text;
-    int texture;
+    Texture texture;
     int x,y,w,h;
     float r,g,b;
     float effectfade;
@@ -19,7 +19,7 @@ struct MenuItem {
     float linestartsize;
     float lineendsize;
 
-    void init(MenuItemType _type, int _id, const string& _text, int _texture,
+    void init(MenuItemType _type, int _id, const string& _text, Texture _texture,
             int _x, int _y, int _w, int _h, float _r, float _g, float _b,
             float _linestartsize=1, float _lineendsize=1){
         type=_type;
@@ -51,31 +51,31 @@ void Menu::clearMenu(){
 
 void Menu::addLabel(int id,const string& text,int x,int y,float r,float g,float b){
     items.push_back(MenuItem());
-    items.back().init(MenuItem::LABEL,id,text,0,x,y,-1,-1,r,g,b);
+    items.back().init(MenuItem::LABEL,id,text,Texture(),x,y,-1,-1,r,g,b);
 }
 void Menu::addButton(int id,const string& text,int x,int y,float r,float g,float b){
     items.push_back(MenuItem());
-    items.back().init(MenuItem::BUTTON,id,text,0,x,y,-1,-1,r,g,b);
+    items.back().init(MenuItem::BUTTON,id,text,Texture(),x,y,-1,-1,r,g,b);
 }
-void Menu::addImage(int id,int texture,int x,int y,int w,int h,float r,float g,float b){
+void Menu::addImage(int id,Texture texture,int x,int y,int w,int h,float r,float g,float b){
     items.push_back(MenuItem());
     items.back().init(MenuItem::IMAGE,id,"",texture,x,y,w,h,r,g,b);
 }
-void Menu::addButtonImage(int id,int texture,int x,int y,int w,int h,float r,float g,float b){
+void Menu::addButtonImage(int id,Texture texture,int x,int y,int w,int h,float r,float g,float b){
     items.push_back(MenuItem());
     items.back().init(MenuItem::IMAGEBUTTON,id,"",texture,x,y,w,h,r,g,b);
 }
 void Menu::addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r,float g,float b){
     items.push_back(MenuItem());
-    items.back().init(MenuItem::MAPLINE,-1,"",0,x,y,w,h,r,g,b,startsize,endsize);
+    items.back().init(MenuItem::MAPLINE,-1,"",Texture(),x,y,w,h,r,g,b,startsize,endsize);
 }
-void Menu::addMapMarker(int id,int texture,int x,int y,int w,int h,float r,float g,float b){
+void Menu::addMapMarker(int id,Texture texture,int x,int y,int w,int h,float r,float g,float b){
     items.push_back(MenuItem());
     items.back().init(MenuItem::MAPMARKER,id,"",texture,x,y,w,h,r,g,b);
 }
 void Menu::addMapLabel(int id,const string& text,int x,int y,float r,float g,float b){
     items.push_back(MenuItem());
-    items.back().init(MenuItem::MAPLABEL,id,text,0,x,y,-1,-1,r,g,b);
+    items.back().init(MenuItem::MAPLABEL,id,text,Texture(),x,y,-1,-1,r,g,b);
 }
 
 void Menu::setText(int id,const string& text){
@@ -148,7 +148,7 @@ void Menu::drawItems(){
             }else{
                 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
             }
-            glBindTexture(GL_TEXTURE_2D,it->texture);
+            it->texture.bind();
                        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
             glBegin(GL_QUADS);
index a4a2e9c5b90a92a042a14887faae856615cbd0f1..6a1911af746c6735afc67831e91fba17f27d3436 100644 (file)
@@ -7,10 +7,10 @@ namespace Menu {
     void clearMenu();
     void addLabel(int id,const string& text,int x,int y,float r=1,float g=0,float b=0);
     void addButton(int id,const string& text,int x,int y,float r=1,float g=0,float b=0);
-    void addImage(int id,int texture,int x,int y,int w,int h,float r=1,float g=1,float b=1);
-    void addButtonImage(int id,int texture,int x,int y,int w,int h,float r=1,float g=1,float b=1);
+    void addImage(int id,Texture texture,int x,int y,int w,int h,float r=1,float g=1,float b=1);
+    void addButtonImage(int id,Texture texture,int x,int y,int w,int h,float r=1,float g=1,float b=1);
     void addMapLine(int x, int y, int w, int h, float startsize, float endsize, float r,float g,float b);
-    void addMapMarker(int id,int texture,int x,int y,int w,int h,float r,float g,float b);
+    void addMapMarker(int id,Texture texture,int x,int y,int w,int h,float r,float g,float b);
     void addMapLabel(int id,const string& text,int x,int y,float r=1,float g=0,float b=0);
     void setText(int id,const string& text);
     void setText(int id,const string& text,int x,int y,int w,int h);
index bdc44dcdd2182a76278f95c4641a85ab1006d890..95b93fe4c489d238a2efe1afbfd6e1b04fdc7885 100644 (file)
@@ -524,7 +524,7 @@ bool Model::load(const char *filename,bool texture )
                funpackf(tfile, "Bf Bf Bf", &Triangles[i].gy[0], &Triangles[i].gy[1], &Triangles[i].gy[2]);
        }
 
-       Texture.xsz=0;
+       modelTexture.xsz=0;
 
        fclose(tfile);
 
@@ -607,7 +607,7 @@ bool Model::loaddecal(const char *filename,bool texture )
        }
 
 
-       Texture.xsz=0;
+       modelTexture.xsz=0;
 
        fclose(tfile);
 
@@ -878,7 +878,7 @@ void Model::CalculateNormals(bool facenormalise)
 
 void Model::drawimmediate()
 {
-       glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr);
+       textureptr.bind();
        glBegin(GL_TRIANGLES);
        for(int i=0;i<TriangleNum;i++){
                /*if(Triangles[i].vertex[0]<vertexNum&&Triangles[i].vertex[1]<vertexNum&&Triangles[i].vertex[2]<vertexNum&&Triangles[i].vertex[0]>=0&&Triangles[i].vertex[1]>=0&&Triangles[i].vertex[2]>=0){
@@ -919,7 +919,7 @@ void Model::draw()
 
        if(!color)glInterleavedArrays( GL_T2F_N3F_V3F,8*sizeof(GLfloat),&vArray[0]);
        if(color)glInterleavedArrays( GL_T2F_C3F_V3F,8*sizeof(GLfloat),&vArray[0]);
-       glBindTexture(GL_TEXTURE_2D,(unsigned long)textureptr);
+       textureptr.bind();
 
 #if PLATFORM_MACOSX
        glLockArraysEXT( 0, TriangleNum*3);
@@ -937,6 +937,7 @@ void Model::draw()
        //drawimmediate();
 }
 
+//TODO: phase out in favor of Texture
 void Model::drawdifftex(GLuint texture)
 {
        glEnableClientState(GL_NORMAL_ARRAY);
@@ -950,6 +951,35 @@ void Model::drawdifftex(GLuint texture)
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
 
 
+#ifndef WIN32
+       glLockArraysEXT( 0, TriangleNum*3);
+#endif
+       glDrawArrays(GL_TRIANGLES, 0, TriangleNum*3);
+#ifndef WIN32
+       glUnlockArraysEXT();
+#endif
+
+
+       if(!color)glDisableClientState(GL_NORMAL_ARRAY);
+       if(color)glDisableClientState(GL_COLOR_ARRAY);
+       glDisableClientState(GL_VERTEX_ARRAY);
+       glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+       //drawdiffteximmediate(texture);
+}
+
+void Model::drawdifftex(Texture texture)
+{
+       glEnableClientState(GL_NORMAL_ARRAY);
+       glEnableClientState(GL_VERTEX_ARRAY);
+       glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+       if(!color)glInterleavedArrays( GL_T2F_N3F_V3F,8*sizeof(GLfloat),&vArray[0]);
+       if(color)glInterleavedArrays( GL_T2F_C3F_V3F,8*sizeof(GLfloat),&vArray[0]);
+
+       texture.bind();
+       glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
+       glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
+
+
 #ifndef WIN32
        glLockArraysEXT( 0, TriangleNum*3);
 #endif
@@ -999,7 +1029,7 @@ void Model::drawdiffteximmediate(GLuint texture)
        glEnd();
 }
 
-void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtexture2,GLuint breaktexture)
+void Model::drawdecals(Texture shadowtexture,Texture bloodtexture,Texture bloodtexture2,Texture breaktexture)
 {
        if(decals){
                if(type!=decalstype)return;
@@ -1023,7 +1053,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext
                        if(decaltype[i]==blooddecalfast&&decalalivetime[i]<2)decalalivetime[i]=2;
 
                        if(decaltype[i]==shadowdecal&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, shadowtexture);
+                               shadowtexture.bind();
                                if(!blend){
                                        blend=1;
                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -1031,7 +1061,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext
                                }
                        }
                        if(decaltype[i]==breakdecal&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, breaktexture);
+                               breaktexture.bind();
                                if(!blend){
                                        blend=1;
                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -1039,7 +1069,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext
                                }
                        }
                        if((decaltype[i]==blooddecal||decaltype[i]==blooddecalslow)&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, bloodtexture);
+                               bloodtexture.bind();
                                if(blend){
                                        blend=0;
                                        glAlphaFunc(GL_GREATER, 0.15);
@@ -1047,7 +1077,7 @@ void Model::drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtext
                                }
                        }
                        if((decaltype[i]==blooddecalfast)&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, bloodtexture2);
+                               bloodtexture2.bind();
                                if(blend){
                                        blend=0;
                                        glAlphaFunc(GL_GREATER, 0.15);
@@ -1385,8 +1415,7 @@ void Model::MakeDecal(int atype, XYZ where,float size, float opacity, float rota
 Model::~Model()
 {
        deallocate();
-
-       glDeleteTextures( 1, &textureptr );
+    textureptr.destroy();
 }
 
 void Model::deallocate()
@@ -1474,8 +1503,7 @@ Model::Model()
        Triangles=0;
        vArray=0;
 
-       textureptr = 0;
-       memset(&Texture, 0, sizeof(Texture));
+       memset(&modelTexture, 0, sizeof(modelTexture));
        numpossible = 0;
        color = 0;
 
index caad18ed653699c7b1c6436153dafe2ae99a6401..a82f85d04287ec55a750fddebfb80ed5364da274 100644 (file)
@@ -35,6 +35,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Terrain.h"
 #include "binio.h"
 #include "Quaternions.h"
+#include "Texture.h"
 
 //
 // Textures List
@@ -85,8 +86,8 @@ public:
        TexturedTriangle Triangles[max_textured_triangle];
        GLfloat vArray[max_textured_triangle*24];*/
 
-       GLuint                          textureptr;
-       ModelTexture            Texture;
+       Texture textureptr;
+       ModelTexture modelTexture;
        int numpossible;
        bool color;
 
@@ -116,7 +117,7 @@ public:
        void DeleteDecal(int which);
        void MakeDecal(int atype, XYZ *where, float *size, float *opacity, float *rotation);
        void MakeDecal(int atype, XYZ where, float size, float opacity, float rotation);
-       void drawdecals(GLuint shadowtexture,GLuint bloodtexture,GLuint bloodtexture2,GLuint breaktexture);
+       void drawdecals(Texture shadowtexture,Texture bloodtexture,Texture bloodtexture2,Texture breaktexture);
        int SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate);
        int SphereCheckPossible(XYZ *p1,float radius, XYZ *move, float *rotate);
        int LineCheck(XYZ *p1,XYZ *p2, XYZ *p, XYZ *move, float *rotate);
@@ -139,6 +140,7 @@ public:
        void CalculateNormals(bool facenormalise);
        void draw();
        void drawdifftex(GLuint texture);
+       void drawdifftex(Texture texture);
        void drawimmediate();
        void drawdiffteximmediate(GLuint texture);
        void Rotate(float xang,float yang,float zang);
index de603c1655d52fe58c341943efd904d81a0da6b6..8f2544f905df5a3666839c95130deaf479d75263 100644 (file)
@@ -759,10 +759,6 @@ Objects::Objects()
        center = 0;
        radius = 0;
        numobjects = 0;
-       boxtextureptr = 0;
-       treetextureptr = 0;
-       bushtextureptr = 0;
-       rocktextureptr = 0;
 
        memset(position, 0, sizeof(position));
        memset(type, 0, sizeof(type));
@@ -787,9 +783,9 @@ Objects::Objects()
 
 Objects::~Objects()
 {
-       glDeleteTextures( 1, &boxtextureptr );
-       glDeleteTextures( 1, &treetextureptr );
-       glDeleteTextures( 1, &bushtextureptr );
-       glDeleteTextures( 1, &rocktextureptr );
+    boxtextureptr.destroy();
+    treetextureptr.destroy();
+    bushtextureptr.destroy();
+    rocktextureptr.destroy();
 };
 
index 4d35552acd773694affea99fd543070c06ca2467..a99c646f7e445b240629d0a59f660cc67c999c2d 100644 (file)
@@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Models.h"
 #include "Terrain.h"
 #include "Sprite.h"
+#include "Texture.h"
 #include <vector>
 //
 // Model Structures
@@ -73,10 +74,10 @@ public:
        float scale[max_objects];
        float messedwith[max_objects];
        float checked[max_objects];
-       GLuint  boxtextureptr;
-       GLuint  treetextureptr;
-       GLuint  bushtextureptr;
-       GLuint  rocktextureptr;
+       Texture boxtextureptr;
+       Texture treetextureptr;
+       Texture bushtextureptr;
+       Texture rocktextureptr;
        float shadowed[max_objects];
        float occluded[max_objects];
        bool checkcollide(XYZ startpoint, XYZ endpoint,int which);
index 4a9898f14b0f9d3894486145151d7db3b1471a78..87a4bbe952169d8071309255f4847fe9ab399da5 100644 (file)
@@ -475,7 +475,7 @@ void Person::DoBloodBig(float howmuch,int which){
                                                                        }
                                                                }
                                                        }
-                                                       glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
+                                                       skeleton.drawmodel.textureptr.bind();
                                                        DoMipmaps();
 
                                                        bleedxint=0;
@@ -703,7 +703,7 @@ bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
                                                                        }
                                                                }
                                                        }
-                                                       glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
+                                                       skeleton.drawmodel.textureptr.bind();
                                                        DoMipmaps();
 
                                                        bleedy=(1+coordsy)*512;
@@ -3858,7 +3858,7 @@ void      Person::DoStuff(){
        if(bleeding>0){
                bleeding-=multiplier*.3;
                if(bloodtoggle==2){
-                       glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
+                       skeleton.drawmodel.textureptr.bind();
                        if(bleeding<=0&&(detail!=2||osx))DoMipmaps();
                }
        }
@@ -3984,7 +3984,7 @@ void      Person::DoStuff(){
                        }
                }
                if(!osx&&detail>1){
-                       glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
+                       skeleton.drawmodel.textureptr.bind();
                        DoMipmaps();
                }
 
index 8832a65dbd981527d9ef05f5c32166c03dd716f4..f37a0ee310ba561e0b6a7bc4aeb4c5a617b75742 100644 (file)
@@ -412,7 +412,7 @@ class Person
                void DoHead();
                void DoMipmaps()
                {
-                 glBindTexture(GL_TEXTURE_2D, skeleton.drawmodel.textureptr);
+                 skeleton.drawmodel.textureptr.bind();
           glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
                  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skeleton.skinsize, skeleton.skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0]);
                }
index f42dd4d87534af4ccf50f769e4e6aa8553829d78..bf145f23b965128a15671f29dfe44290d86c4936 100644 (file)
@@ -34,12 +34,12 @@ void
 SkyBox::load (const char *ffront, const char *fleft, const char *fback,
              const char *fright, const char *fup,   const char *fdown)
 {
-       Game::LoadTexture(ffront, &front, true, false);
-       Game::LoadTexture(fleft,  &left,  true, false);
-       Game::LoadTexture(fback,  &back,  true, false);
-       Game::LoadTexture(fright, &right, true, false);
-       Game::LoadTexture(fup,    &up,    true, false);
-       Game::LoadTexture(fdown,  &down,  true, false);
+       front.load(ffront, true, false);
+       left.load(fleft, true, false);
+       back.load(fback, true, false);
+       right.load(fright, true, false);
+       up.load(fup, true, false);
+       down.load(fdown, true, false);
 }
 
 void   SkyBox::draw()
@@ -66,7 +66,7 @@ void  SkyBox::draw()
        glDisable(GL_LIGHTING);
        if(skyboxtexture)glEnable(GL_TEXTURE_2D);
        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-       glBindTexture(GL_TEXTURE_2D, front); 
+       front.bind(); 
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
        glBegin(GL_QUADS);
@@ -76,7 +76,7 @@ void  SkyBox::draw()
        glTexCoord2f(1, 1); glVertex3f( size,  size,  size);
        glTexCoord2f(0, 1); glVertex3f(-size,  size,  size);
        glEnd();
-       glBindTexture(GL_TEXTURE_2D, back);
+       back.bind();
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
        glBegin(GL_QUADS);
@@ -86,7 +86,7 @@ void  SkyBox::draw()
        glTexCoord2f(0, 1); glVertex3f( size,  size, -size);
        glTexCoord2f(0, 0); glVertex3f( size, -size, -size);
        glEnd();
-       glBindTexture(GL_TEXTURE_2D, up);
+       up.bind();
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
        glBegin(GL_QUADS);
@@ -96,7 +96,7 @@ void  SkyBox::draw()
        glTexCoord2f(1, 0); glVertex3f( size,  size,  size);
        glTexCoord2f(1, 1); glVertex3f( size,  size, -size);
        glEnd();
-       glBindTexture(GL_TEXTURE_2D, down);
+       down.bind();
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
        glBegin(GL_QUADS);
@@ -107,7 +107,7 @@ void        SkyBox::draw()
        glTexCoord2f(1, 1); glVertex3f( size, -size,  size);
        glTexCoord2f(0, 1); glVertex3f(-size, -size,  size);
        glEnd();
-       glBindTexture(GL_TEXTURE_2D, right);
+       right.bind();
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
        glBegin(GL_QUADS);
@@ -117,7 +117,7 @@ void        SkyBox::draw()
        glTexCoord2f(0, 1); glVertex3f( size,  size,  size);
        glTexCoord2f(0, 0); glVertex3f( size, -size,  size);
        glEnd();
-       glBindTexture(GL_TEXTURE_2D, left);
+       left.bind();
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
        glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
        glBegin(GL_QUADS);
@@ -134,11 +134,11 @@ void      SkyBox::draw()
 
 SkyBox::~SkyBox()
 {
-       glDeleteTextures( 1, &front );
-       glDeleteTextures( 1, &left );
-       glDeleteTextures( 1, &back );
-       glDeleteTextures( 1, &right );
-       glDeleteTextures( 1, &up );
-       glDeleteTextures( 1, &down );
+    front.destroy();
+    left.destroy();
+    back.destroy();
+    right.destroy();
+    up.destroy();
+    down.destroy();
 };
 
index dc602ce216c78d92e7a54daa4a62c37e93575e8b..f1f54229aa36f61c5353162414db9999da9cec8b 100644 (file)
@@ -26,16 +26,17 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "TGALoader.h"
 #include "Quaternions.h"
 #include "gamegl.h"
+#include "Texture.h"
 
 class SkyBox{
 public:
-       GLuint front, left, back, right, up, down;
+       Texture front, left, back, right, up, down;
 
        void load(const char *ffront, const char *fleft, const char *fback,
                  const char *fright, const char *fup,   const char *fdown);
        void draw();
 
-       SkyBox(): front(0), left(0), back(0), right(0), up(0), down(0) {}
+       SkyBox() {}
        ~SkyBox();
 };
 
index 79a5af45a6cf37150524e7f5acd789e03f84f50a..334a6f5f5c827d4b1f3005667bc79bfb4382d798 100644 (file)
@@ -38,17 +38,17 @@ extern int bloodtoggle;
 extern XYZ windvector;
 
 // init statics
-GLuint Sprite::cloudtexture = 0;
-GLuint Sprite::cloudimpacttexture = 0;
-GLuint Sprite::bloodtexture = 0;
-GLuint Sprite::flametexture = 0;
-GLuint Sprite::bloodflametexture = 0;
-GLuint Sprite::smoketexture = 0;
-GLuint Sprite::snowflaketexture = 0;
-GLuint Sprite::shinetexture = 0;
-GLuint Sprite::splintertexture = 0;
-GLuint Sprite::leaftexture = 0;
-GLuint Sprite::toothtexture = 0;
+Texture Sprite::cloudtexture;
+Texture Sprite::cloudimpacttexture;
+Texture Sprite::bloodtexture;
+Texture Sprite::flametexture;
+Texture Sprite::bloodflametexture;
+Texture Sprite::smoketexture;
+Texture Sprite::snowflaketexture;
+Texture Sprite::shinetexture;
+Texture Sprite::splintertexture;
+Texture Sprite::leaftexture;
+Texture Sprite::toothtexture;
 
 float Sprite::checkdelay = 0;
 
@@ -101,7 +101,7 @@ void Sprite::Draw()
                if(lasttype!=sprites[i]->type) {
                        switch(sprites[i]->type) {
                                case cloudsprite:
-                                       glBindTexture( GL_TEXTURE_2D, cloudtexture);
+                                       cloudtexture.bind();
                                        if(!blend){
                                                blend=1;
                                                glAlphaFunc(GL_GREATER, 0.0001);
@@ -109,7 +109,7 @@ void Sprite::Draw()
                                        }
                                break;
                                case cloudimpactsprite:
-                                       glBindTexture( GL_TEXTURE_2D, cloudimpacttexture);
+                                       cloudimpacttexture.bind();
                                        if(!blend){
                                                blend=1;
                                                glAlphaFunc(GL_GREATER, 0.0001);
@@ -117,7 +117,7 @@ void Sprite::Draw()
                                        }
                                break;
                                case breathsprite:
-                                       glBindTexture( GL_TEXTURE_2D, cloudimpacttexture);
+                                       cloudimpacttexture.bind();
                                        if(!blend){
                                                blend=1;
                                                glAlphaFunc(GL_GREATER, 0.0001);
@@ -125,7 +125,7 @@ void Sprite::Draw()
                                        }
                                break;
                                case smoketype:
-                                       glBindTexture( GL_TEXTURE_2D, smoketexture);
+                                       smoketexture.bind();
                                        if(!blend){
                                                blend=1;
                                                glAlphaFunc(GL_GREATER, 0.0001);
@@ -133,7 +133,7 @@ void Sprite::Draw()
                                        }
                                break;
                                case bloodsprite:
-                                       glBindTexture( GL_TEXTURE_2D, bloodtexture);
+                                       bloodtexture.bind();
                                        if(!blend){
                                                blend=1;
                                                glAlphaFunc(GL_GREATER, 0.0001);
@@ -142,10 +142,10 @@ void Sprite::Draw()
                                break;
                                case splintersprite :
                                        if(lastspecial!=sprites[i]->special) {
-                                               if(sprites[i]->special==0)glBindTexture( GL_TEXTURE_2D, splintertexture);
-                                               if(sprites[i]->special==1)glBindTexture( GL_TEXTURE_2D, leaftexture);
-                                               if(sprites[i]->special==2)glBindTexture( GL_TEXTURE_2D, snowflaketexture);
-                                               if(sprites[i]->special==3)glBindTexture( GL_TEXTURE_2D, toothtexture);
+                                               if(sprites[i]->special==0)splintertexture.bind();
+                                               if(sprites[i]->special==1)leaftexture.bind();
+                                               if(sprites[i]->special==2)snowflaketexture.bind();
+                                               if(sprites[i]->special==3)toothtexture.bind();
                                                if(!blend){
                                                        blend=1;
                                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -154,7 +154,7 @@ void Sprite::Draw()
                                        }
                                break;
                                case snowsprite:
-                                       glBindTexture( GL_TEXTURE_2D, snowflaketexture);
+                                       snowflaketexture.bind();
                                        if(!blend){
                                                blend=1;
                                                glAlphaFunc(GL_GREATER, 0.0001);
@@ -162,7 +162,7 @@ void Sprite::Draw()
                                        }
                                break;
                                case weaponshinesprite:
-                                       glBindTexture( GL_TEXTURE_2D, shinetexture);
+                                       shinetexture.bind();
                                        if(blend){
                                                blend=0;
                                                glAlphaFunc(GL_GREATER, 0.001);
@@ -171,7 +171,7 @@ void Sprite::Draw()
                                break;
                                case flamesprite:
                                case weaponflamesprite:
-                                       glBindTexture( GL_TEXTURE_2D, flametexture);
+                                       flametexture.bind();
                                        if(blend||lasttype==bloodflamesprite){
                                                blend=0;
                                                glAlphaFunc(GL_GREATER, 0.3);
@@ -179,7 +179,7 @@ void Sprite::Draw()
                                        }
                                break;
                                case bloodflamesprite:
-                                       glBindTexture( GL_TEXTURE_2D, bloodflametexture);
+                                       bloodflametexture.bind();
                                        if(blend){
                                                blend=0;
                                                glAlphaFunc(GL_GREATER, 0.3);
@@ -438,16 +438,16 @@ Sprite::Sprite()
 
 void Sprite::clearTextures()
 {
-       glDeleteTextures( 1, &toothtexture );
-       glDeleteTextures( 1, &cloudtexture );
-       glDeleteTextures( 1, &cloudimpacttexture );
-       glDeleteTextures( 1, &bloodtexture );
-       glDeleteTextures( 1, &flametexture );
-       glDeleteTextures( 1, &bloodflametexture );
-       glDeleteTextures( 1, &smoketexture );
-       glDeleteTextures( 1, &snowflaketexture );
-       glDeleteTextures( 1, &shinetexture );
-       glDeleteTextures( 1, &splintertexture );
-       glDeleteTextures( 1, &leaftexture );
+       toothtexture.destroy();
+       cloudtexture.destroy();
+       cloudimpacttexture.destroy();
+       bloodtexture.destroy();
+       flametexture.destroy();
+       bloodflametexture.destroy();
+       smoketexture.destroy();
+       snowflaketexture.destroy();
+       shinetexture.destroy();
+       splintertexture.destroy();
+       leaftexture.destroy();
 }
 
index 7f25a8425e386f3623c7ef4c8f3238b447bdfe34..819db208edc45fed7b19a96e8a73d77cf9bc9def 100644 (file)
@@ -30,6 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Lights.h"
 #include "Terrain.h"
 #include "Objects.h"
+#include "Texture.h"
 
 #include <vector>
 
@@ -88,20 +89,20 @@ class Sprite{
                }
                static void clearTextures();
                
-               static GLuint cloudtexture;
-               static GLuint bloodtexture;
-               static GLuint flametexture;
-               static GLuint smoketexture;
+               static Texture cloudtexture;
+               static Texture bloodtexture;
+               static Texture flametexture;
+               static Texture smoketexture;
                
-               static GLuint cloudimpacttexture;
-               static GLuint snowflaketexture;
-               static GLuint shinetexture;
-               static GLuint bloodflametexture;
+               static Texture cloudimpacttexture;
+               static Texture snowflaketexture;
+               static Texture shinetexture;
+               static Texture bloodflametexture;
                
-               static GLuint splintertexture;
+               static Texture splintertexture;
                
-               static GLuint leaftexture;
-               static GLuint toothtexture;
+               static Texture leaftexture;
+               static Texture toothtexture;
 
                Sprite();
                ~Sprite();
index acdc3223465261c58b3288f09516173756d13207..ecc8757b7dc953971759fb7a595eff6a1b587cd6 100644 (file)
@@ -1047,7 +1047,7 @@ void Terrain::drawdecals()
                for(i=0;i<numdecals;i++){
                        if(decaltype[i]==blooddecalfast&&decalalivetime[i]<2)decalalivetime[i]=2;
                        if((decaltype[i]==shadowdecal||decaltype[i]==shadowdecalpermanent)&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, shadowtexture);
+                               shadowtexture.bind();
                                if(!blend){
                                        blend=1;
                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -1055,7 +1055,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if(decaltype[i]==footprintdecal&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, footprinttexture);
+                               footprinttexture.bind();
                                if(!blend){
                                        blend=1;
                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -1063,7 +1063,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if(decaltype[i]==bodyprintdecal&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, bodyprinttexture);
+                               bodyprinttexture.bind();
                                if(!blend){
                                        blend=1;
                                        glAlphaFunc(GL_GREATER, 0.0001);
@@ -1071,7 +1071,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if((decaltype[i]==blooddecal||decaltype[i]==blooddecalslow)&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, bloodtexture);
+                               bloodtexture.bind();
                                if(blend){
                                        blend=0;
                                        glAlphaFunc(GL_GREATER, 0.15);
@@ -1079,7 +1079,7 @@ void Terrain::drawdecals()
                                }
                        }
                        if((decaltype[i]==blooddecalfast)&&decaltype[i]!=lasttype){
-                               glBindTexture( GL_TEXTURE_2D, bloodtexture2);
+                               bloodtexture2.bind();
                                if(blend){
                                        blend=0;
                                        glAlphaFunc(GL_GREATER, 0.15);
@@ -1516,13 +1516,6 @@ void Terrain::DoShadows()
 
 Terrain::Terrain()
 {
-       bloodtexture = 0;
-       bloodtexture2 = 0;
-       shadowtexture = 0;
-       footprinttexture = 0;
-       bodyprinttexture = 0;
-       breaktexture = 0;
-       terraintexture = 0;
        size = 0;
 
        memset(patchobjectnum, 0, sizeof(patchobjectnum));
@@ -1563,12 +1556,12 @@ Terrain::Terrain()
 }
 Terrain::~Terrain()
 {
-       glDeleteTextures( 1, &terraintexture );
-       glDeleteTextures( 1, &shadowtexture );
-       glDeleteTextures( 1, &bodyprinttexture );
-       glDeleteTextures( 1, &footprinttexture );
-       glDeleteTextures( 1, &bloodtexture );
-       glDeleteTextures( 1, &bloodtexture2 );
-       glDeleteTextures( 1, &breaktexture );
+       terraintexture.destroy();
+       shadowtexture.destroy();
+       bodyprinttexture.destroy();
+       footprinttexture.destroy();
+       bloodtexture.destroy();
+       bloodtexture2.destroy();
+       breaktexture.destroy();
 }
 
index 4a3746dc7bbf63f818b1456c65b5ed1addd1c9fc..051065617675b5e259580423a81c386c4b885cbc 100644 (file)
@@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "TGALoader.h"
 #include "Quaternions.h"
 #include "Quaternions.h"
+#include "Texture.h"
 
 #define max_terrain_size                       256             
 #define curr_terrain_size                      size
@@ -58,13 +59,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 class Terrain{
 public:
-       GLuint bloodtexture;
-       GLuint bloodtexture2;
-       GLuint shadowtexture;
-       GLuint footprinttexture;
-       GLuint bodyprinttexture;
-       GLuint breaktexture;
-       GLuint terraintexture;
+       Texture bloodtexture;
+       Texture bloodtexture2;
+       Texture shadowtexture;
+       Texture footprinttexture;
+       Texture bodyprinttexture;
+       Texture breaktexture;
+       Texture terraintexture;
        short   size;
 
        int patchobjectnum[subdivision][subdivision];
index 11b1c8d083f67a6ef3524d7ef35060a4b1acbdd2..8f9b1524ef99757edea61e64fc2f5713c8819ea8 100644 (file)
@@ -32,7 +32,7 @@ void Text::LoadFontTexture(const char *fileName)
 
        LOG(std::string("Loading font texture...") + fileName);
 
-       Game::LoadTexture(fileName, &FontTexture, false, false);
+       FontTexture.load(fileName, false, false);
 /*
        //Load Image
        //LoadTGA( fileName ); 
@@ -86,7 +86,7 @@ void Text::BuildFont()                                                                // Build Our Font Display List
 
 //     base=glGenLists(256);                                                           // Creating 256 Display Lists
        base=glGenLists(512);                                                           // Creating 256 Display Lists
-       glBindTexture(GL_TEXTURE_2D, FontTexture);                      // Select Our Font Texture
+       FontTexture.bind();
        for (loop=0; loop<512; loop++)                                          // Loop Through All 256 Lists
        {
                if (loop < 256)
@@ -130,7 +130,7 @@ void Text::_glPrint(float x, float y, const char *string, int set, float size, f
                set=1;
        }
        glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-       glBindTexture(GL_TEXTURE_2D, FontTexture);                      // Select Our Font Texture
+       FontTexture.bind();
        glDisable(GL_DEPTH_TEST);                                                       // Disables Depth Testing
        glDisable(GL_LIGHTING);
        glEnable(GL_BLEND);
@@ -181,18 +181,14 @@ void Text::glPrintOutlined(float r, float g, float b, float x, float y, const ch
        glPrint( x,  y, string,  set,  size,  width,  height);
 }
 
-Text::Text()
-{
+Text::Text() {
        base = 0;
-       FontTexture = 0;
 }
-Text::~Text()
-{
-       if (base)
-       {
+Text::~Text() {
+       if (base) {
                glDeleteLists(base, 512);
                base = 0;
        }
-       glDeleteTextures( 1, &FontTexture );
+       FontTexture.destroy();
 }
 
index eba21593e81082014951c7a547ec411455b7dac0..cec999569450723082be3f462a8cde904575561c 100644 (file)
@@ -29,10 +29,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Quaternions.h"
 #include "gamegl.h"
 #include "TGALoader.h"
+#include "Texture.h"
 
 class Text{
 public:
-       GLuint FontTexture;
+       Texture FontTexture;
        GLuint base;
 
        void LoadFontTexture(const char *fileName);
index 11f421129df60970ddbc7e5d088c21dadacbcd59..5c8834d70be6e83ec69a6b6fa5b3bf5cf078293c 100644 (file)
 
 using namespace std;
 
-map<string,Texture> Texture::textures;
-
 extern TGAImageRec texture;
 extern bool trilinear;
 
-Texture::~Texture()  {
-       free(array);
-    glDeleteTextures(1,&id);
-}
 
-void Texture::load()  {
-       GLuint type;
+class TextureRes {
+private:
+    static vector<TextureRes*> list;
 
-       LOGFUNC;
+    GLuint id;
+    string filename;
+    bool hasMipmap;
+    bool hasAlpha;
+    bool isSkin;
+    int skinsize;
+    GLubyte* data;
+    int datalen;
 
-       LOG(std::string("Loading texture...") + fileName);
+    void load();
 
-       unsigned char fileNamep[256];
-       CopyCStringToPascal(ConvertFileName(fileName.c_str()), fileNamep);
-       //Load Image
-       upload_image( fileNamep ,hasalpha);
-       
-       //Alpha channel?
-       if ( texture.bpp == 24 )
-               type = GL_RGB;
-       else
-               type = GL_RGBA;
-
-       glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-       if(!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(mipmap)
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (trilinear?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR_MIPMAP_NEAREST) );
-       else
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-       glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
+public:
+    TextureRes(const string& filename, bool hasMipmap, bool hasAlpha);
+    TextureRes(const string& filename, bool hasMipmap, GLubyte* array, int* skinsize);
+    ~TextureRes();
+    void bind();
+
+    static void reloadAll();
+};
+
+
+vector<TextureRes*> TextureRes::list;
+
+void TextureRes::load(){
+    //load image into 'texture' global var
+       unsigned char filenamep[256];
+       CopyCStringToPascal(ConvertFileName(filename.c_str()),filenamep);
+       upload_image(filenamep,hasAlpha);
        
        skinsize=texture.sizeX;
+       GLuint type=GL_RGBA;
+       if(texture.bpp==24)
+               type=GL_RGB;
        
-       if(isSkin) {
-               int tempnum=0;
-               int nb = (texture.sizeY*texture.sizeX*(texture.bpp/8));
-               array = (GLubyte*)malloc(nb*sizeof(GLubyte));
-               for(int i=0;i<nb;i++) {
-                       if((i+1)%4||type==GL_RGB) {
-                               array[tempnum]=texture.data[i];
-                               tempnum++;
-                       }
-               }
-               arraySize=tempnum;
-
-        glTexImage2D( GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, array );
-       } else {
-        glTexImage2D( GL_TEXTURE_2D, 0, type, texture.sizeX, texture.sizeY, 0, type, GL_UNSIGNED_BYTE, texture.data );
+       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);
        }
 }
 
-GLuint Texture::Load(const string& fileName, bool mipmap, bool hasalpha) {
-       map<string,Texture>::iterator it = textures.find(fileName);
-       if(it==textures.end()) {
-               textures.insert(make_pair(fileName,Texture(fileName,mipmap,hasalpha)));
-               textures[fileName].load();
-               return textures[fileName].getId();
-       } else {
-               return it->second.getId();
-       }
+void TextureRes::bind(){
+    glBindTexture(GL_TEXTURE_2D,id);
 }
 
-GLuint Texture::Load(const string& fileName, bool mipmap, bool hasalpha, GLubyte* array, int* skinsize) {
-       map<string,Texture>::iterator it = textures.find(fileName);
-       if(it==textures.end()) {
-               textures.insert(make_pair(fileName,Texture(fileName,mipmap,hasalpha,true)));
-               textures[fileName].load();
-               *skinsize = textures[fileName].skinsize;
-               for(int i=0;i<textures[fileName].arraySize;i++) {
-                       array[i] = textures[fileName].array[i];
-               }
-               return textures[fileName].getId();
-       } else {
-               *skinsize = it->second.skinsize;
-               for(int i=0;i<it->second.arraySize;i++) {
-                       array[i] = it->second.array[i];
-               }
-               return it->second.getId();
-       }
+TextureRes::TextureRes(const string& _filename, bool _hasMipmap, bool _hasAlpha):
+    id(0),filename(_filename),hasMipmap(_hasMipmap),hasAlpha(_hasAlpha),isSkin(false),
+    skinsize(0),data(NULL),datalen(0) {
+    load();
+    list.push_back(this);
+}
+
+TextureRes::TextureRes(const string& _filename, bool _hasMipmap, GLubyte* array, int* skinsizep):
+    id(0),filename(_filename),hasMipmap(_hasMipmap),hasAlpha(false),isSkin(true),
+    skinsize(0),data(NULL),datalen(0) {
+    load();
+    *skinsizep=skinsize;
+    for(int i=0;i<datalen;i++)
+        array[i]=data[i];
+    list.push_back(this);
+}
+
+TextureRes::~TextureRes(){
+    free(data);
+    glDeleteTextures(1,&id);
+    for(vector<TextureRes*>::iterator it=list.begin();it!=list.end();it++)
+        if(*it==this){
+            list.erase(it);
+            break;
+        }
+}
+
+void TextureRes::reloadAll(){
+    for(vector<TextureRes*>::iterator it=list.begin();it!=list.end();it++)
+        (*it)->load();
+}
+
+
+
+
+void Texture::load(const string& filename, bool hasMipmap, bool hasAlpha){
+    destroy();
+    tex=new TextureRes(filename,hasMipmap,hasAlpha);
+}
+
+void Texture::load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep){
+    destroy();
+    tex=new TextureRes(filename,hasMipmap,array,skinsizep);
+}
+
+void Texture::destroy(){
+    if(tex){
+        delete tex;
+        tex=NULL;
+    }
+}
+
+void Texture::bind(){
+    if(tex)
+        tex->bind();
+    else
+        glBindTexture(GL_TEXTURE_2D,0);
+}
+
+void Texture::reloadAll(){
+    TextureRes::reloadAll();
 }
 
index f50af0eef4c44c32bad01637a749cd0c3fd903db..a684bd53f565e5d4e589a3c6b0a15006bafa139f 100644 (file)
@@ -2,39 +2,23 @@
 #define _TEXTURE_H_
 
 #include <map>
+#include <vector>
 #include <string>
+using namespace std;
 
-//keeps track of which textures are loaded
-class Texture {
-       private:
-               static std::map<std::string,Texture> textures;
-       
-               bool isSkin;
-               std::string fileName;
-               GLuint id;
-               bool mipmap;
-               bool hasalpha;
-               GLubyte* array;
-               int arraySize;
-               int skinsize;
+class TextureRes;
 
-               void load();
+class Texture {
+private:
+    TextureRes* tex;
+public:
+    inline Texture(): tex(NULL) {}
+    void load(const string& filename, bool hasMipmap, bool hasAlpha);
+    void load(const string& filename, bool hasMipmap, GLubyte* array, int* skinsizep);
+    void destroy();
+    void bind();
 
-       public:
-               Texture():
-                       isSkin(false), skinsize(0), arraySize(0),
-                       fileName(""), id(0), mipmap(false), hasalpha(false), array(NULL) { }
-               ~Texture();
-               Texture (const std::string& _fileName, bool _mipmap, bool _hasalpha):
-                       isSkin(false), skinsize(0), arraySize(0), array(NULL),
-                       fileName(_fileName), id(0), mipmap(_mipmap), hasalpha(_hasalpha) { }
-               Texture (const std::string& _fileName, bool _mipmap, bool _hasalpha, bool _isSkin):
-                       isSkin(_isSkin), skinsize(0), arraySize(0), array(NULL),
-                       fileName(_fileName), id(0), mipmap(_mipmap), hasalpha(_hasalpha) { }
-               GLuint getId() const { return id; }
-               
-               static GLuint Load(const std::string& fileName, bool mipmap, bool hasalpha);
-               static GLuint Load(const std::string& fileName, bool mipmap, bool hasalpha, GLubyte* array, int* skinsize);
+    static void reloadAll();
 };
 
 #endif
index 4d8f32ec7cddf536780d416e701cdadd3df2986d..a7d587fca88a1d2958683a620563d373cd89f4ff 100644 (file)
@@ -54,17 +54,17 @@ extern int tutoriallevel;
 extern int numthrowkill;
 
 Model Weapon::throwingknifemodel;
-GLuint Weapon::knifetextureptr = 0;
-GLuint Weapon::lightbloodknifetextureptr = 0;
-GLuint Weapon::bloodknifetextureptr = 0;
+Texture Weapon::knifetextureptr;
+Texture Weapon::lightbloodknifetextureptr;
+Texture Weapon::bloodknifetextureptr;
 
 Model Weapon::swordmodel;
-GLuint Weapon::swordtextureptr = 0;
-GLuint Weapon::lightbloodswordtextureptr = 0;
-GLuint Weapon::bloodswordtextureptr = 0;
+Texture Weapon::swordtextureptr;
+Texture Weapon::lightbloodswordtextureptr;
+Texture Weapon::bloodswordtextureptr;
 
 Model Weapon::staffmodel;
-GLuint Weapon::stafftextureptr = 0;
+Texture Weapon::stafftextureptr;
 
 Weapon::Weapon(int t, int o) : owner(o) {
        setType(t);
@@ -1073,12 +1073,12 @@ Weapons::Weapons()
 
 Weapons::~Weapons()
 {
-       glDeleteTextures( 1, &Weapon::stafftextureptr );
-       glDeleteTextures( 1, &Weapon::knifetextureptr );
-       glDeleteTextures( 1, &Weapon::lightbloodknifetextureptr );
-       glDeleteTextures( 1, &Weapon::bloodknifetextureptr );
-       glDeleteTextures( 1, &Weapon::swordtextureptr );
-       glDeleteTextures( 1, &Weapon::lightbloodswordtextureptr );
-       glDeleteTextures( 1, &Weapon::bloodswordtextureptr );
+       Weapon::stafftextureptr.destroy();
+       Weapon::knifetextureptr.destroy();
+       Weapon::lightbloodknifetextureptr.destroy();
+       Weapon::bloodknifetextureptr.destroy();
+       Weapon::swordtextureptr.destroy();
+       Weapon::lightbloodswordtextureptr.destroy();
+       Weapon::bloodswordtextureptr.destroy();
 }
 
index bb178c1c928198e6160880e7659d476a75efe24c..6b2ebbaa8dac0128147ed8c4fa81d14f7715549f 100644 (file)
@@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Terrain.h"
 #include "Sprite.h"
 #include "Person.h"
+#include "Texture.h"
 #include <cmath>
 
 #define max_weapons 30
@@ -45,17 +46,17 @@ class Weapon {
                Weapon(int type, int owner);
                        
                static Model throwingknifemodel;
-               static GLuint knifetextureptr;
-               static GLuint lightbloodknifetextureptr;
-               static GLuint bloodknifetextureptr;
+               static Texture knifetextureptr;
+               static Texture lightbloodknifetextureptr;
+               static Texture bloodknifetextureptr;
 
                static Model swordmodel;
-               static GLuint swordtextureptr;
-               static GLuint lightbloodswordtextureptr;
-               static GLuint bloodswordtextureptr;
+               static Texture swordtextureptr;
+               static Texture lightbloodswordtextureptr;
+               static Texture bloodswordtextureptr;
 
                static Model staffmodel;
-               static GLuint stafftextureptr;
+               static Texture stafftextureptr;
        
                void Draw();
                void DoStuff(int);