]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Skybox.cpp
major refactor of texture system
[lugaru.git] / Source / Skybox.cpp
index 811029ae92b9757704b579ec04128e0798f637a3..bf145f23b965128a15671f29dfe44290d86c4936 100644 (file)
@@ -23,234 +23,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Game.h"
 
 extern float viewdistance;
-extern int detail;
-extern bool trilinear;
 extern float blurness;
 extern int environment;
-extern TGAImageRec texture;
 extern bool skyboxtexture;
 extern float skyboxr;
 extern float skyboxg;
 extern float skyboxb;
-extern int tutoriallevel;
 
-bool   SkyBox::load( const char *ffront,const char *fleft,const char *fback,const char *fright,const char *fup,const char *fdown,const char *fcloud,const char *freflect)
+void
+SkyBox::load (const char *ffront, const char *fleft, const char *fback,
+             const char *fright, const char *fup,   const char *fdown)
 {
-/*     static GLuint           type;
-       unsigned char fileNamep[256];
-*/
-       LOGFUNC;
-
-       //front
-       Game::LoadTexture(ffront, &front, true, false);
-       //left
-       Game::LoadTexture(fleft, &left, true, false);
-       //back
-       Game::LoadTexture(fback, &back, true, false);
-       //right
-       Game::LoadTexture(fright, &right, true, false);
-       //up
-       Game::LoadTexture(fup, &up, true, false);
-       //down
-       Game::LoadTexture(fdown, &down, true, false);
-       //cloud
-       Game::LoadTexture(fcloud, &cloud, true, false);
-       //reflect
-       Game::LoadTexture(freflect, &reflect, true, false);
-/*
-       //front
-       CopyCStringToPascal(ffront,fileNamep);
-       upload_image( fileNamep ,0); 
-       if(1==1){
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!front)glGenTextures( 1, &front );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, front);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-
-       }
-
-       //left
-       CopyCStringToPascal(fleft,fileNamep);
-       upload_image( fileNamep ,0); 
-       if(1==1){
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!left)glGenTextures( 1, &left );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, left);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-
-       }
-
-       //back
-       CopyCStringToPascal(fback,fileNamep);
-       upload_image( fileNamep ,0); 
-       if(1==1){
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!back)glGenTextures( 1, &back );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, back);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-
-       }
-
-       //right
-       CopyCStringToPascal(fright,fileNamep);
-       upload_image( fileNamep ,0); 
-       if(1==1){
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!right)glGenTextures( 1, &right );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, right);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-
-       }
-
-       //up
-       CopyCStringToPascal(fup,fileNamep);
-       upload_image( fileNamep ,0); 
-       if(1==1){
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!up)glGenTextures( 1, &up );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, up);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-
-       }
-
-       //down
-       CopyCStringToPascal(fdown,fileNamep);
-       upload_image( fileNamep ,0); 
-       if(1==1){
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!down)glGenTextures( 1, &down );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, down);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-
-       }
-
-       //cloud
-       CopyCStringToPascal(fcloud,fileNamep);
-       upload_image( fileNamep ,0); 
-       if(1==1){
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!cloud)glGenTextures( 1, &cloud );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, cloud);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-
-       }
-
-       //up
-       CopyCStringToPascal(freflect,fileNamep);
-       upload_image( fileNamep ,0); 
-       if(1==1){
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!reflect)glGenTextures( 1, &reflect );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, reflect);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               if(trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-
-       }
-*/
-       return true;
+       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()
@@ -263,7 +52,6 @@ void SkyBox::draw()
        M[13]=0;
        M[14]=0;
        glLoadMatrixf(M);
-       //if(environment==2)glTranslatef(0,blurness*viewdistance/1000,0);
        if(environment==2)glScalef(1+blurness/1000,1,1+blurness/1000);
        if(environment!=2)glColor3f(.85*skyboxr,.85*skyboxg,.95*skyboxb);
        else glColor3f(1*skyboxr,.95*skyboxg,.95*skyboxb);
@@ -276,10 +64,9 @@ void        SkyBox::draw()
        glDisable(GL_CULL_FACE);
        glEnable(GL_BLEND);
        glDisable(GL_LIGHTING);
-       //              glActiveTextureARB(GL_TEXTURE0_ARB);
        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);
@@ -289,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);
@@ -299,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);
@@ -309,8 +96,7 @@ void SkyBox::draw()
        glTexCoord2f(1, 0); glVertex3f( size,  size,  size);
        glTexCoord2f(1, 1); glVertex3f( size,  size, -size);
        glEnd();
-       //if(detail!=0){
-       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);
@@ -321,8 +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);
@@ -332,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);
@@ -342,39 +127,18 @@ void      SkyBox::draw()
        glTexCoord2f(1, 1); glVertex3f(-size,  size,  size);
        glTexCoord2f(0, 1); glVertex3f(-size,  size, -size);
        glEnd();
-       /*
-       glEnable(GL_BLEND);
-       glColor4f(1,1,1,1);
-       glBindTexture(GL_TEXTURE_2D, cloud);
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
-       glBegin(GL_QUADS);
-       glNormal3f( 0.0f, -1.0f, 0);
-       glTexCoord2f(0,                                 (1+cloudmove)*30);      glVertex3f(-size,       size/200, -size);
-       glTexCoord2f(0,                                 0);                             glVertex3f(-size,       size/200,  size);
-       glTexCoord2f((1+cloudmove)*30,  0);                             glVertex3f( size,       size/200,  size);
-       glTexCoord2f((1+cloudmove)*30,  (1+cloudmove)*30);      glVertex3f( size,       size/200, -size);
-       glEnd();
-       glDisable(GL_BLEND);*/
        glEnable(GL_CULL_FACE);
        glDepthMask(1);
        glPopMatrix();
 }
 
-SkyBox::SkyBox()
-{
-       front = 0,left = 0,back = 0,right = 0,up = 0,down = 0,cloud = 0,reflect = 0;
-       cloudmove = 0;
-}
 SkyBox::~SkyBox()
 {
-       if (front) glDeleteTextures( 1, &front );
-       if (left) glDeleteTextures( 1, &left );
-       if (back) glDeleteTextures( 1, &back );
-       if (right) glDeleteTextures( 1, &right );
-       if (up) glDeleteTextures( 1, &up );
-       if (down) glDeleteTextures( 1, &down );
-       if (cloud) glDeleteTextures( 1, &cloud );
-       if (reflect) glDeleteTextures( 1, &reflect );
+    front.destroy();
+    left.destroy();
+    back.destroy();
+    right.destroy();
+    up.destroy();
+    down.destroy();
 };