From 6d9ead11533a1cdd9a892ad989609f9755f23120 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Fri, 7 Jan 2011 21:06:29 +0300 Subject: [PATCH] Minor SkyBox cleanup --- Source/GameTick.cpp | 13 +-- Source/Skybox.cpp | 250 ++------------------------------------------ Source/Skybox.h | 8 +- 3 files changed, 14 insertions(+), 257 deletions(-) diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 383052e..3281f6b 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -1332,9 +1332,7 @@ void Game::Setenvironment(int which) ":Data:Textures:Skybox(snow):Back.jpg", ":Data:Textures:Skybox(snow):Right.jpg", ":Data:Textures:Skybox(snow):Up.jpg", - ":Data:Textures:Skybox(snow):Down.jpg", - ":Data:Textures:Skybox(snow):Cloud.jpg", - ":Data:Textures:Skybox(snow):Reflect.jpg"); + ":Data:Textures:Skybox(snow):Down.jpg"); @@ -1373,9 +1371,7 @@ void Game::Setenvironment(int which) ":Data:Textures:Skybox(sand):Back.jpg", ":Data:Textures:Skybox(sand):Right.jpg", ":Data:Textures:Skybox(sand):Up.jpg", - ":Data:Textures:Skybox(sand):Down.jpg", - ":Data:Textures:Skybox(sand):Cloud.jpg", - ":Data:Textures:Skybox(sand):Reflect.jpg"); + ":Data:Textures:Skybox(sand):Down.jpg"); @@ -1413,9 +1409,7 @@ void Game::Setenvironment(int which) ":Data:Textures:Skybox(grass):Back.jpg", ":Data:Textures:Skybox(grass):Right.jpg", ":Data:Textures:Skybox(grass):Up.jpg", - ":Data:Textures:Skybox(grass):Down.jpg", - ":Data:Textures:Skybox(grass):Cloud.jpg", - ":Data:Textures:Skybox(grass):Reflect.jpg"); + ":Data:Textures:Skybox(grass):Down.jpg"); @@ -4149,7 +4143,6 @@ void Game::Tick() dialoguetime+=multiplier; - skybox.cloudmove+=multiplier; hawkrotation+=multiplier*25; realhawkcoords=0; realhawkcoords.x=25; diff --git a/Source/Skybox.cpp b/Source/Skybox.cpp index 811029a..5c4aaab 100644 --- a/Source/Skybox.cpp +++ b/Source/Skybox.cpp @@ -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(fleft, &left, true, false); + Game::LoadTexture(fback, &back, true, false); 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; + Game::LoadTexture(fup, &up, true, false); + Game::LoadTexture(fdown, &down, 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,7 +64,6 @@ 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); @@ -309,7 +96,6 @@ 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); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); @@ -321,7 +107,6 @@ void SkyBox::draw() glTexCoord2f(1, 1); glVertex3f( size, -size, size); glTexCoord2f(0, 1); glVertex3f(-size, -size, size); glEnd(); - //} glBindTexture(GL_TEXTURE_2D, right); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); @@ -342,30 +127,11 @@ 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 ); @@ -374,7 +140,5 @@ SkyBox::~SkyBox() 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 ); }; diff --git a/Source/Skybox.h b/Source/Skybox.h index aa9e1f7..dc602ce 100644 --- a/Source/Skybox.h +++ b/Source/Skybox.h @@ -29,13 +29,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. class SkyBox{ public: - GLuint front,left,back,right,up,down,cloud,reflect; - float cloudmove; + GLuint front, left, back, right, up, down; - bool 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 load(const char *ffront, const char *fleft, const char *fback, + const char *fright, const char *fup, const char *fdown); void draw(); - SkyBox(); + SkyBox(): front(0), left(0), back(0), right(0), up(0), down(0) {} ~SkyBox(); }; -- 2.39.5