From f7f3989db89536a13751c11625168948a08e03e0 Mon Sep 17 00:00:00 2001 From: sf17k Date: Fri, 6 May 2011 20:02:20 -0400 Subject: [PATCH] toggle fullscreen with alt+enter --- Source/Game.cpp | 2 ++ Source/Game.h | 39 +++++++++++++++++++--- Source/GameInitDispose.cpp | 67 +++++++++++++++++++++----------------- Source/GameTick.cpp | 8 ++--- Source/OpenGL_Windows.cpp | 13 +++++--- Source/Text.cpp | 6 ++-- 6 files changed, 90 insertions(+), 45 deletions(-) diff --git a/Source/Game.cpp b/Source/Game.cpp index 1002b0a..66aafdf 100644 --- a/Source/Game.cpp +++ b/Source/Game.cpp @@ -26,6 +26,8 @@ int directing; float dialoguetime; int dialoguegonethrough[20]; +std::vector Game::textures; + Game::Game() { terraintexture = 0; diff --git a/Source/Game.h b/Source/Game.h index 92a6945..56b65c2 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -61,13 +61,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern GLuint rabbittexture; +struct TextureInfo; + class Game { public: - typedef std::map TextureList; - typedef std::map GLTextureList; - typedef TextureList::iterator TexIter; - static TextureList textures; + static std::vector textures; GLuint terraintexture; GLuint terraintexture2; @@ -220,9 +219,12 @@ class Game static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha); static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize); + static void LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha); + static void LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload); void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize); - bool AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize); + bool AddClothes(const char *fileName, GLubyte *array); void InitGame(); + void LoadScreenTexture(); void LoadStuff(); void LoadingScreen(); void FadeLoadingScreen(float howmuch); @@ -298,6 +300,33 @@ class Game Account* accountactive; }; +//keeps track of which textures are loaded +//TODO: delete them properly +struct TextureInfo{ + bool isLoaded; + bool isSkin; + const char* fileName; + GLuint* ptextureid; + int mipmap; + bool hasalpha; + GLubyte* array; + int* skinsize; + + void load(){ + if(isSkin) + Game::LoadTextureSaveData(fileName,ptextureid,mipmap,array,skinsize,isLoaded); + else + Game::LoadTextureData(fileName,ptextureid,mipmap,hasalpha); + isLoaded=true; + } + TextureInfo(const char *_fileName, GLuint *_ptextureid,int _mipmap, bool _hasalpha): + isLoaded(false), isSkin(false), array(NULL), skinsize(NULL), + fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), hasalpha(_hasalpha) { } + TextureInfo(const char *_fileName, GLuint *_ptextureid, int _mipmap, GLubyte *_array, int *_skinsize): + isLoaded(false), isSkin(true), hasalpha(false), + fileName(_fileName), ptextureid(_ptextureid), mipmap(_mipmap), array(_array), skinsize(_skinsize) { } +}; + #ifndef __forceinline # ifdef __GNUC__ # define __forceinline inline __attribute__((always_inline)) diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 79d8bd1..f87d6ee 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -99,8 +99,6 @@ void LOG(const std::string &fmt, ...) } -Game::TextureList Game::textures; - void Game::Dispose() { int i,j; @@ -114,13 +112,7 @@ void Game::Dispose() Account::saveFile(":Data:Users", accountactive); - TexIter it = textures.begin(); - for (; it != textures.end(); ++it) - { - if (glIsTexture(it->second)) - glDeleteTextures(1, &it->second); - } - textures.clear(); + //textures.clear(); LOG("Shutting down sound system..."); @@ -145,7 +137,17 @@ void Game::Dispose() } -void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha) +void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha){ + textures.push_back(TextureInfo(fileName,textureid,mipmap,hasalpha)); + textures.back().load(); +} + +void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize){ + textures.push_back(TextureInfo(fileName,textureid,mipmap,array,skinsize)); + textures.back().load(); +} + +void Game::LoadTextureData(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha) { GLuint type; @@ -191,7 +193,7 @@ void Game::LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool } } -void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize) +void Game::LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload) { GLuint type; int i; @@ -236,12 +238,12 @@ void Game::LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GL if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); int tempnum=0; - for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++){ - if((i+1)%4||type==GL_RGB){ - array[tempnum]=texture.data[i]; - tempnum++; - } - } + if(!reload) + for(i=0;i<(int)(texture.sizeY*texture.sizeX*bytesPerPixel);i++) + if((i+1)%4||type==GL_RGB){ + array[tempnum]=texture.data[i]; + tempnum++; + } *skinsize=texture.sizeX; @@ -294,7 +296,7 @@ void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte } } -bool Game::AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize) +bool Game::AddClothes(const char *fileName, GLubyte *array) { int i; int bytesPerPixel; @@ -875,6 +877,22 @@ void Game::InitGame() } +void Game::LoadScreenTexture(){ + glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); + + if(!screentexture) + glGenTextures( 1, &screentexture ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); + + + glEnable(GL_TEXTURE_2D); + glBindTexture( GL_TEXTURE_2D, screentexture); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0); +} + void Game::LoadStuff() { static float temptexdetail; @@ -1190,18 +1208,7 @@ void Game::LoadStuff() //if(ismotionblur){ if(!screentexture){ - glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); - - glGenTextures( 1, &screentexture ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - - - glEnable(GL_TEXTURE_2D); - glBindTexture( GL_TEXTURE_2D, screentexture); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); - - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, kTextureSize, kTextureSize, 0); + LoadScreenTexture(); } if(targetlevel!=7){ diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index f662c5a..ee3ddea 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -639,7 +639,7 @@ static void set_clothes(int pnum, Game *game, const char *args) char buf[64]; snprintf(buf, 63, ":Data:Textures:%s.png", args); - if (!game->AddClothes(buf,0,1,&player[pnum].skeleton.skinText[pnum],&player[pnum].skeleton.skinsize)) + if (!game->AddClothes(buf,&player[pnum].skeleton.skinText[pnum])) return; player[pnum].DoMipmaps(); @@ -1955,7 +1955,7 @@ void Game::Loadlevel(const char *name){ tintr=player[i].clothestintr[j]; tintg=player[i].clothestintg[j]; tintb=player[i].clothestintb[j]; - AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize); + AddClothes((char *)player[i].clothes[j],&player[i].skeleton.skinText[0]); } player[i].DoMipmaps(); } @@ -3148,7 +3148,7 @@ void Game::doDebugKeys(){ tintr=player[closest].clothestintr[i]; tintg=player[closest].clothestintg[i]; tintb=player[closest].clothestintb[i]; - AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize); + AddClothes((char *)player[closest].clothes[i],&player[closest].skeleton.skinText[0]); } player[closest].DoMipmaps(); } @@ -3628,7 +3628,7 @@ void Game::doDebugKeys(){ tintr=player[numplayers].clothestintr[i]; tintg=player[numplayers].clothestintg[i]; tintb=player[numplayers].clothestintb[i]; - AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize); + AddClothes((char *)player[numplayers].clothes[i],&player[numplayers].skeleton.skinText[0]); } if(player[numplayers].numclothes){ player[numplayers].DoMipmaps(); diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index c74939e..cc8103c 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -236,8 +236,6 @@ void initGL(){ fprintf(stderr, "Failed to initialize stereo, disabling.\n"); stereomode = stereoNone; } - - //TODO: load textures here } static void toggleFullscreen(){ @@ -248,7 +246,13 @@ static void toggleFullscreen(){ screen=SDL_SetVideoMode(0,0,0,flags); if(!screen) exit(1); + //reload opengl state initGL(); + for(std::vector::iterator it=Game::textures.begin(); it!=Game::textures.end(); it++){ + it->load(); + } + pgame->text.BuildFont(); + pgame->LoadScreenTexture(); } static void sdlEventProc(const SDL_Event &e, Game &game){ @@ -358,8 +362,9 @@ Boolean SetUp (Game & game) } Uint32 sdlflags = SDL_OPENGL; - if (!cmdline("windowed")) - sdlflags |= SDL_FULLSCREEN; + //TODO: commented out temporarily + //if (!cmdline("windowed")) + //sdlflags |= SDL_FULLSCREEN; SDL_WM_SetCaption("Lugaru", "Lugaru"); diff --git a/Source/Text.cpp b/Source/Text.cpp index 0652c87..4c22f0f 100644 --- a/Source/Text.cpp +++ b/Source/Text.cpp @@ -78,8 +78,10 @@ void Text::BuildFont() // Build Our Font Display List if (base) { - LOG("Font already created..."); - return; + glDeleteLists(base, 512); + base = 0; + //LOG("Font already created..."); + //return; } // base=glGenLists(256); // Creating 256 Display Lists -- 2.39.2