]> git.jsancho.org Git - lugaru.git/commitdiff
added alt+enter fullscreen toggle
authorsf17k <sf171k@gmail.com>
Wed, 8 Jun 2011 13:42:13 +0000 (09:42 -0400)
committersf17k <sf171k@gmail.com>
Wed, 8 Jun 2011 13:42:13 +0000 (09:42 -0400)
Source/OpenGL_Windows.cpp
Source/Texture.cpp

index e064f99d2362aad372358a5665b4b947c526ad5b..1abe2f1d28abbe5110b1f60b818d7a3e5eb7f824 100644 (file)
@@ -237,21 +237,25 @@ void initGL(){
 }
 
 static void toggleFullscreen(){
-       SDL_WM_ToggleFullScreen(SDL_GetVideoSurface());
-    //~ SDL_Surface* screen=SDL_GetVideoSurface();
-    //~ Uint32 flags=screen->flags;
-    //~ screen=SDL_SetVideoMode(0,0,0,flags^SDL_FULLSCREEN);
-    //~ if(!screen)
-        //~ 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();
+       if(!SDL_WM_ToggleFullScreen(SDL_GetVideoSurface())){
+        SDL_Surface* screen=SDL_GetVideoSurface();
+        Uint32 flags=screen->flags;
+        screen=SDL_SetVideoMode(0,0,0,flags^SDL_FULLSCREEN);
+        if(!screen)
+            screen=SDL_SetVideoMode(0,0,0,flags);
+        if(!screen)
+            exit(1);
+        //reload opengl state
+        initGL();
+        Texture::reloadAll();
+        if(text)
+            text->BuildFont();
+        if(firstload){
+            screentexture=0;
+            LoadScreenTexture();
+        }
+        screentexture2=0;
+    }
 }
 
 static void sdlEventProc(const SDL_Event &e)
index 5c8834d70be6e83ec69a6b6fa5b3bf5cf078293c..ef20536da7b37f7268607d0a52ba0e44df69569e 100644 (file)
@@ -20,6 +20,7 @@ private:
     int skinsize;
     GLubyte* data;
     int datalen;
+    GLubyte* skindata;
 
     void load();
 
@@ -37,9 +38,11 @@ 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);
+    if(!skindata){
+        unsigned char filenamep[256];
+        CopyCStringToPascal(ConvertFileName(filename.c_str()),filenamep);
+        upload_image(filenamep,hasAlpha);
+    }
        
        skinsize=texture.sizeX;
        GLuint type=GL_RGBA;
@@ -62,14 +65,18 @@ void TextureRes::load(){
     }
        
        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);
+        if(skindata){
+            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, skinsize, skinsize, 0, GL_RGB, GL_UNSIGNED_BYTE, skindata);
+        }else{
+            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);
        }
@@ -81,18 +88,19 @@ void TextureRes::bind(){
 
 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) {
+    skinsize(0),data(NULL),datalen(0),skindata(NULL) {
     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) {
+    skinsize(0),data(NULL),datalen(0),skindata(NULL) {
     load();
     *skinsizep=skinsize;
     for(int i=0;i<datalen;i++)
         array[i]=data[i];
+    skindata=array;
     list.push_back(this);
 }
 
@@ -107,8 +115,10 @@ TextureRes::~TextureRes(){
 }
 
 void TextureRes::reloadAll(){
-    for(vector<TextureRes*>::iterator it=list.begin();it!=list.end();it++)
+    for(vector<TextureRes*>::iterator it=list.begin();it!=list.end();it++){
+        (*it)->id=0;
         (*it)->load();
+    }
 }