]> git.jsancho.org Git - lugaru.git/commitdiff
toggle fullscreen with alt+enter
authorsf17k <sf171k@gmail.com>
Sat, 7 May 2011 00:02:20 +0000 (20:02 -0400)
committersf17k <sf171k@gmail.com>
Sat, 7 May 2011 00:02:20 +0000 (20:02 -0400)
Source/Game.cpp
Source/Game.h
Source/GameInitDispose.cpp
Source/GameTick.cpp
Source/OpenGL_Windows.cpp
Source/Text.cpp

index 1002b0a9c4af0c71491840ee69422bdeca3c0003..66aafdf565c0afcc003bf3f63e820fb659f39980 100644 (file)
@@ -26,6 +26,8 @@ int directing;
 float dialoguetime;
 int dialoguegonethrough[20];
 
+std::vector<TextureInfo> Game::textures;
+
 Game::Game()
 {
        terraintexture = 0;
index 92a6945f7ad290109030dbee4d474976881b7fbd..56b65c257773b5510c9ec39ad6f4db4a3300398b 100644 (file)
@@ -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<std::string, GLuint> TextureList;
-               typedef std::map<GLuint, std::string> GLTextureList;
-               typedef TextureList::iterator TexIter;
-               static TextureList textures;
+               static std::vector<TextureInfo> 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))
index 79d8bd150578f9ff49b39d31471464c6d35f86b9..f87d6eef92349de6e5c7fadf3c98e55f6a86a7f6 100644 (file)
@@ -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){
index f662c5a36951a13297c2593c47d1cc9ea096fbd5..ee3ddea78f1d5bd032e38034d633747b971b29a2 100644 (file)
@@ -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();
index c74939ec77a30f3472b2e3c6e9aece7263eb7561..cc8103ce8e80e7cfbbf61f4093006d0c421c3aea 100644 (file)
@@ -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<TextureInfo>::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");
 
index 0652c87b2d4085820d13aeef395a496f15dfe9a1..4c22f0fd973e08b0a85e47298fc0ab1bfa47ea95 100644 (file)
@@ -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