]> git.jsancho.org Git - lugaru.git/commitdiff
Refactor of the texture system
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Tue, 17 May 2011 08:58:51 +0000 (10:58 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Tue, 17 May 2011 08:58:51 +0000 (10:58 +0200)
CMakeLists.txt
Source/Game.cpp
Source/Game.h
Source/GameDraw.cpp
Source/GameInitDispose.cpp
Source/GameTick.cpp
Source/OpenGL_Windows.cpp
Source/TGALoader.cpp

index 4775a5ec9eeb1a6d75139967d163090259844df7..5b0d0ab163cd5ab328a10cb1e93cc2b58fdbb6bb 100644 (file)
@@ -69,6 +69,7 @@ set(LUGARU_SRCS
        ${SRCDIR}/Skybox.cpp
        ${SRCDIR}/Sprite.cpp
        ${SRCDIR}/Terrain.cpp
+       ${SRCDIR}/Texture.cpp
        ${SRCDIR}/Text.cpp
        ${SRCDIR}/TGALoader.cpp
        ${SRCDIR}/unpack.c
@@ -99,6 +100,7 @@ set(LUGARU_H
        ${SRCDIR}/Sprite.h
        ${SRCDIR}/TGALoader.h
        ${SRCDIR}/Terrain.h
+       ${SRCDIR}/Texture.h
        ${SRCDIR}/Text.h
        ${SRCDIR}/Weapons.h
        ${SRCDIR}/Input.h
index 82d23eca73bb4523ea1486a0e7a7864263c5b6fc..77b9a5b21cda64a480dc3f230f8c129fba868934 100644 (file)
@@ -26,8 +26,6 @@ int directing;
 float dialoguetime;
 int dialoguegonethrough[20];
 
-std::vector<TextureInfo> Game::textures;
-
 Game::Game()
 {
        terraintexture = 0;
index 431f3243e8f6622931416b17dae35a07ec4ba76b..cb08024bc41559667f6098fc148a6bfa43ad2b1f 100644 (file)
@@ -155,8 +155,6 @@ public:
 class Game
 {
        public:
-               static std::vector<TextureInfo> textures;
-
                GLuint terraintexture;
                GLuint terraintexture2;
                GLuint terraintexture3;
@@ -284,10 +282,8 @@ class Game
                unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey;
                bool oldattackkey;
 
-               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);
+               static void LoadTexture(const string fileName, GLuint *textureid,int mipmap, bool hasalpha);
+               static void LoadTextureSave(const string fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
                void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
         bool AddClothes(const char *fileName, GLubyte *array);
                void InitGame();
@@ -370,33 +366,6 @@ 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 0f3dd8cd07e277e8473b41ddd5bbcdd9d82c78bd..522681bc781434e18e23a23e21d4274ebc963956 100644 (file)
@@ -2034,13 +2034,11 @@ void Game::LoadCampaign() {
        }
        ipstream.close();
 
-       if(!Mainmenuitems[7]) {
-               ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
-               if(test.good()) {
-                       LoadTextureData((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
-               } else {
-                       LoadTextureData(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
-               }
+       ifstream test(ConvertFileName((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str()));
+       if(test.good()) {
+               LoadTexture((":Data:Textures:"+accountactive->getCurrentCampaign()+":World.png").c_str(),&Mainmenuitems[7],0,0);
+       } else {
+               LoadTexture(":Data:Textures:World.png",&Mainmenuitems[7],0,0);
        }
 
        if(accountactive->getCampaignChoicesMade()==0) {
index b2716e930732d3e76bc56f80e94bc9cb3f6d4045..eb55bb39fb04c548dda355eba633d036fd4bf40c 100644 (file)
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Game.h"
 #include "openal_wrapper.h"
 #include "Animation.h"
+#include "Texture.h"
 
 extern float screenwidth,screenheight;
 extern float viewdistance;
@@ -98,7 +99,6 @@ void LOG(const std::string &fmt, ...)
     // !!! FIXME: write me.
 }
 
-
 void Game::Dispose()
 {
        LOGFUNC;
@@ -135,124 +135,12 @@ void Game::Dispose()
 }
 
 
-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::LoadTexture(const string fileName, GLuint *textureid,int mipmap, bool hasalpha) {
+       *textureid = Texture::Load(fileName,mipmap,hasalpha);
 }
 
-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;
-
-       LOGFUNC;
-
-       LOG(std::string("Loading texture...") + fileName);
-
-       // Fix filename so that is os appropreate
-       char * fixedFN = ConvertFileName(fileName);
-
-       unsigned char fileNamep[256];
-       CopyCStringToPascal(fixedFN, fileNamep);
-       //Load Image
-       upload_image( fileNamep ,hasalpha);
-
-//     std::string fname(fileName);
-//     std::transform(fname.begin(), fname.end(), tolower);
-//     TexIter it = textures.find(fname);
-
-       //Is it valid?
-       if(1==1)
-       //if(textures.end() == it)
-       {
-               //Alpha channel?
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!*textureid)
-                       glGenTextures( 1, textureid );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, *textureid);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-               if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-               
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, type, GL_UNSIGNED_BYTE, texture.data );
-       }
-}
-
-void Game::LoadTextureSaveData(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize, bool reload)
-{
-       GLuint          type;
-       int i;
-       int bytesPerPixel;
-
-       LOGFUNC;
-
-       LOG(std::string("Loading texture (S)...") + fileName);
-
-       //Load Image
-       unsigned char fileNamep[256];
-       CopyCStringToPascal(ConvertFileName(fileName), fileNamep);
-       //Load Image
-       upload_image( fileNamep ,0);
-       //LoadTGA( fileName );
-
-//     std::string fname(fileName);
-//     std::transform(fname.begin(), fname.end(), tolower);
-//     TexIter it = textures.find(fname);
-
-       //Is it valid?
-       if(1==1)
-       //if(textures.end() == it)
-       {
-               bytesPerPixel=texture.bpp/8;
-
-               //Alpha channel?
-               if ( texture.bpp == 24 )
-                       type = GL_RGB;
-               else
-                       type = GL_RGBA;
-
-               glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-
-               if(!*textureid)glGenTextures( 1, textureid );
-               glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
-               glBindTexture( GL_TEXTURE_2D, *textureid);
-               glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-               if(trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
-               if(!trilinear)if(mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
-               if(!mipmap)glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
-
-               int tempnum=0;
-        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;
-
-               gluBuild2DMipmaps( GL_TEXTURE_2D, type, texture.sizeX, texture.sizeY, GL_RGB, GL_UNSIGNED_BYTE, array );
-
-//             textures.insert(std::make_pair(fname, *textureid));
-       }
-//     else
-//     {
-//             *textureid = it->second;
-//     }
+void Game::LoadTextureSave(const string fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize) {
+       *textureid = Texture::Load(fileName,mipmap,false,array,skinsize);
 }
 
 void Game::LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize)
@@ -884,8 +772,6 @@ void Game::LoadStuff()
 
        stillloading=1;
 
-       //texture.data = ( GLubyte* )malloc( 1024*1024*4 );
-
        for(i=0;i<maxplayers;i++)
        {
                if (glIsTexture(player[i].skeleton.drawmodel.textureptr))
@@ -895,11 +781,8 @@ void Game::LoadStuff()
                player[i].skeleton.drawmodel.textureptr=0;;
        }
 
-       //temptexdetail=texdetail;
-       //texdetail=1;
        i=abs(Random()%4);
        LoadTexture(":Data:Textures:fire.jpg",&loadscreentexture,1,0);
-       //texdetail=temptexdetail;
 
        temptexdetail=texdetail;
        texdetail=1;
@@ -914,8 +797,6 @@ void Game::LoadStuff()
 
        brightness=100;
 
-
-
        if(detail==2){
                texdetail=1;
        }
@@ -928,22 +809,9 @@ void Game::LoadStuff()
 
        realtexdetail=texdetail;
 
-       /*texdetail/=4;
-       if(texdetail<1)texdetail=1;
-       realtexdetail=texdetail*4;
-       */
        numplayers=1;
 
 
-
-       /*LoadTexture(":Data:Textures:snow.png",&terraintexture,1);
-
-       LoadTexture(":Data:Textures:rock.png",&terraintexture2,1);
-
-       LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
-       */
-
-
        LOG("Loading weapon data...");
 
        LoadTexture(":Data:Textures:knife.png",&Weapon::knifetextureptr,0,1);
@@ -983,8 +851,6 @@ void Game::LoadStuff()
        Weapon::staffmodel.CalculateNormals(1);
        //Weapon::staffmodel.ScaleNormals(-1,-1,-1);
 
-       //temptexdetail=texdetail;
-       //if(texdetail>4)texdetail=4;
        LoadTexture(":Data:Textures:shadow.png",&terrain.shadowtexture,0,1);
 
        LoadTexture(":Data:Textures:blood.png",&terrain.bloodtexture,0,1);
@@ -998,30 +864,11 @@ void Game::LoadStuff()
 
        LoadTexture(":Data:Textures:bodyprint.png",&terrain.bodyprinttexture,0,1);
 
-       /*LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1);
-
-       LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1);
-
-       LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1);
-
-       LoadTexture(":Data:Textures:snowflake.png",&Sprite::snowflaketexture,1);
-
-       LoadTexture(":Data:Textures:flame.png",&Sprite::flametexture,1);
-
-       LoadTexture(":Data:Textures:smoke.png",&Sprite::smoketexture,1);
-       //texdetail=temptexdetail;
-       LoadTexture(":Data:Textures:shine.png",&Sprite::shinetexture,1);*/
-
-
-
        LoadTexture(":Data:Textures:hawk.png",&hawktexture,0,1);
 
        LoadTexture(":Data:Textures:logo.png",&logotexture,0,1);
 
 
-       //LoadTexture(":Data:Textures:box.jpg",&objects.boxtextureptr,1,0);
-
-
        LoadTexture(":Data:Textures:cloud.png",&Sprite::cloudtexture,1,1);
        LoadTexture(":Data:Textures:cloudimpact.png",&Sprite::cloudimpacttexture,1,1);
        LoadTexture(":Data:Textures:bloodparticle.png",&Sprite::bloodtexture,1,1);
@@ -1041,15 +888,10 @@ void Game::LoadStuff()
        viewer=0;
 
 
-
-
        if(detail)kTextureSize=1024;
        if(detail==1)kTextureSize=512;
        if(detail==0)kTextureSize=256;
-
-
-       //drawmode=motionblurmode;
-
+       
        //Set up distant light
        light.color[0]=.95;
        light.color[1]=.95;
@@ -1085,7 +927,6 @@ void Game::LoadStuff()
        hawkcoords.z=terrain.size/2*terrain.scale-5-7;
        hawkcoords.y=terrain.getHeight(hawkcoords.x,hawkcoords.z)+25;
 
-
        eye.load((char *)":Data:Models:eye.solid",1);
        eye.Scale(.03,.03,.03);
        eye.CalculateNormals(0);
@@ -1107,9 +948,6 @@ void Game::LoadStuff()
        mainmenu=0;
 
        firstload=0;
-       //if(targetlevel!=7)
-               Loadlevel(targetlevel);
-
 
        rabbitcoords=player[0].coords;
        rabbitcoords.y=terrain.getHeight(rabbitcoords.x,rabbitcoords.z);
@@ -1176,7 +1014,6 @@ void Game::LoadStuff()
 
        LoadingScreen();
 
-       //if(ismotionblur){
        if(!screentexture){
         LoadScreenTexture();
        }
index cd0a9765ae79bd7a22c20b289833b650e128852e..047c5f133feb8077a0d790bb01e0c808740afb09 100644 (file)
@@ -225,7 +225,7 @@ inline Joint& playerJoint(int playerid, int bodypart){
 inline Joint& playerJoint(Person* pplayer, int bodypart){
     return pplayer->skeleton.joints[pplayer->skeleton.jointlabels[bodypart]]; }
 
-inline float sq(float n){ return n*n; }
+inline float sq(float n) { return n*n; }
 
 inline float stepTowardf(float from, float to, float by){
     if(fabs(from-to)<by) return to;
@@ -1425,6 +1425,7 @@ void Game::Loadlevel(const char *name){
        LOGFUNC;
 
        LOG(std::string("Loading level...") + name);
+       cout << "Loading level..." << name << endl;
 
        if(!gameon)
         visibleloading=1;
@@ -1435,7 +1436,7 @@ void Game::Loadlevel(const char *name){
        gamestarted=1;
 
        numenvsounds=0;
-       //visibleloading=1;
+
        if(tutoriallevel!=-1)
         tutoriallevel=0;
        else
@@ -1443,7 +1444,7 @@ void Game::Loadlevel(const char *name){
 
        if(tutoriallevel==1)
         tutorialstage=0;
-       if(tutorialstage==0){
+       if(tutorialstage==0) {
                tutorialstagetime=0;
                tutorialmaxtime=1;
        }
@@ -1458,8 +1459,12 @@ void Game::Loadlevel(const char *name){
 
        int mapvers;
        FILE *tfile;
+       char* buff=getcwd(NULL,0);
+       cout << buff << " " << FixedFN << endl;
+       free(buff);
        tfile=fopen( FixedFN, "rb" );
-       if(tfile){
+       if(tfile) {
+               cout << "existe" << endl;
                pause_sound(stream_firesound);
                scoreadded=0;
                windialogue=0;
@@ -1527,6 +1532,7 @@ void Game::Loadlevel(const char *name){
                        emit_sound_np(consolesuccesssound);
                        freeze=0;
                        console=false;
+                       cout << "console contente" << endl;
                }
 
                if(!stealthloading){
@@ -2086,6 +2092,8 @@ void Game::Loadlevel(const char *name){
 
                if(!firstload)
                        firstload=1;
+       } else {
+               perror("Soucis");
        }
        leveltime=0;
        loadingstuff=0;
@@ -5626,9 +5634,9 @@ void Game::MenuTick(){
                                                targetlevel=-1;
                                                if(firstload) {
                                                        TickOnceAfter();
-                                                       Loadlevel(-1);
                                                } else
                                                        LoadStuff();
+                                               Loadlevel(-1);
 
                                                mainmenu=0;
                                                gameon=1;
@@ -5658,9 +5666,6 @@ void Game::MenuTick(){
                                                                c=campaigns.begin();
                                                        accountactive->setCurrentCampaign(*c);
                                                }
-                                               if(Mainmenuitems[7])
-                                                       glDeleteTextures(1,&Mainmenuitems[7]); // we delete the world texture so load campaign will reload it
-                                               Mainmenuitems[7] = 0;
                                                LoadCampaign();
                                                break;
                                }
@@ -5712,9 +5717,11 @@ void Game::MenuTick(){
                                        loading=2;
                                        loadtime=0;
                                        targetlevel=selected;
-                                       if(firstload)TickOnceAfter();
-                                       if(!firstload)LoadStuff();
-                                       else Loadlevel(selected);
+                                       if(firstload)
+                                               TickOnceAfter();
+                                       else
+                                               LoadStuff();
+                                       Loadlevel(selected);
                                        campaign=0;
 
                                        mainmenu=0;
@@ -7729,7 +7736,7 @@ void Game::TickOnceAfter(){
                 // 0 = load next level
                 // 1 = go back to level select screen
                 // 2 = stealthload next level
-                               if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1){
+                               if(mainmenu==0&&winfreeze&&(campaignlevels[actuallevel].choosenext)==1) {
                                        if(campaignlevels[actuallevel].nextlevel.empty())
                                                endgame=1;
                                } else if(mainmenu==0&&winfreeze) {
index b25b0cba26dbf01ef8f5fc8d1c546105ee4bbe61..c2091fb66c30036ee27edba036787b2d5a8fce71 100644 (file)
@@ -239,52 +239,45 @@ void initGL(){
 }
 
 static void toggleFullscreen(){
-    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();
+       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();
 }
 
-static void sdlEventProc(const SDL_Event &e, Game &game){
-    switch(e.type){
+static void sdlEventProc(const SDL_Event &e, Game &game)
+{
+    switch(e.type) {
         case SDL_MOUSEMOTION:
             game.deltah += e.motion.xrel;
             game.deltav += e.motion.yrel;
             break;
+
         case SDL_KEYDOWN:
             if ((e.key.keysym.sym == SDLK_g) &&
-                               (e.key.keysym.mod & KMOD_CTRL) &&
-                               !(SDL_GetVideoSurface()->flags & SDL_FULLSCREEN) ) {
-                               SDL_WM_GrabInput( ((SDL_WM_GrabInput(SDL_GRAB_QUERY)==SDL_GRAB_ON) ? SDL_GRAB_OFF:SDL_GRAB_ON) );
-                       } else if ( (e.key.keysym.sym == SDLK_RETURN) && (e.key.keysym.mod & KMOD_ALT) ) {
-                toggleFullscreen();
-            }
-            break;
-        case SDL_ACTIVEEVENT:
-            if(e.active.state&SDL_APPINPUTFOCUS){
-                if(e.active.gain){
-                    SDL_WM_GrabInput(SDL_GRAB_ON);
-                    gameFocused=true;
-                }else{
-                    SDL_WM_GrabInput(SDL_GRAB_OFF);
-                    gameFocused=false;
-                }
+                                (e.key.keysym.mod & KMOD_CTRL) &&
+                                !(SDL_GetVideoSurface()->flags & SDL_FULLSCREEN) ) {
+                                SDL_WM_GrabInput( ((SDL_WM_GrabInput(SDL_GRAB_QUERY)==SDL_GRAB_ON) ? SDL_GRAB_OFF:SDL_GRAB_ON) );
+            } else if ( (e.key.keysym.sym == SDLK_RETURN) && (e.key.keysym.mod & KMOD_ALT) ) {
+                                toggleFullscreen();
             }
             break;
     }
 }
 
 
+
 // --------------------------------------------------------------------------
 
 static Point gMidPoint;
@@ -719,52 +712,51 @@ int main(int argc, char **argv)
 
                        while (!gDone&&!game.quit&&(!game.tryquit))
                        {
-                               //if (IsFocused()) {
-                                       //gameFocused = true;
+                                       if (IsFocused())
+                                       {
+                                                       gameFocused = true;
 
-                                       // check windows messages
+                                                       // check windows messages
                        
-                                       game.deltah = 0;
-                                       game.deltav = 0;
-                                       SDL_Event e;
-                                       if(!game.isWaiting()) {
-                                               // message pump
-                                               while( SDL_PollEvent( &e ) ){
-                            switch(e.type){
-                            case SDL_QUIT:
-                                gDone=true;
-                                break;
-                            default:
-                                sdlEventProc(e, game);
-                                break;
+                                                       game.deltah = 0;
+                                                       game.deltav = 0;
+                                                       SDL_Event e;
+                                                       if(!game.isWaiting()) {
+                                                                       // message pump
+                                                                       while( SDL_PollEvent( &e ) )
+                                                                       {
+                                                                                       if( e.type == SDL_QUIT )
+                                                                                       {
+                                                                                                       gDone=true;
+                                                                                                       break;
+                                                                                       }
+                                                                                       sdlEventProc(e, game);
+                                                                       }
                                                        }
-                                               }
-                                       }
 
-                                       // game
-                                       DoUpdate(game);
-                               /*
-                }
-                else
-                {
-                                       if (gameFocused)
-                                       {
-                                               // allow game chance to pause
-                                               gameFocused = false;
-                                               DoUpdate(game);
+                                                       // game
+                                                       DoUpdate(game);
                                        }
+                                       else
+                                       {
+                                                       if (gameFocused)
+                                                       {
+                                                                       // allow game chance to pause
+                                                                       gameFocused = false;
+                                                                       DoUpdate(game);
+                                                       }
 
-                                       // game is not in focus, give CPU time to other apps by waiting for messages instead of 'peeking'
-                                       SDL_ActiveEvent evt;
-                                       SDL_WaitEvent((SDL_Event*)&evt);
-                                       if (evt.type == SDL_ACTIVEEVENT && evt.gain == 1)
-                                               gameFocused = true;
-                                       else if (evt.type == SDL_QUIT)
-                                               gDone = true;
-                               }
-                */
+                                                       // game is not in focus, give CPU time to other apps by waiting for messages instead of 'peeking'
+                                                       SDL_ActiveEvent evt;
+                                                       SDL_WaitEvent((SDL_Event*)&evt);
+                                                       if (evt.type == SDL_ACTIVEEVENT && evt.gain == 1)
+                                                                       gameFocused = true;
+                                                       else if (evt.type == SDL_QUIT)
+                                                                       gDone = true;
+                                       }
                        }
 
+
                }
                pgame = 0;
 
index 266cdc30ef982dac0daaba1c56fc31ebbb557a58..a5eae85dcc61a37f158b9eae5b91c77df3598016 100644 (file)
@@ -40,7 +40,7 @@ bool upload_image(const unsigned char* filePath, bool hasalpha)
 #if !PLATFORM_MACOSX
 
        // for Windows, just use TGA loader for now
-       char fileName[ 256];
+       char fileName[256];
        CopyPascalStringToC( filePath, fileName);
 /*
        // change extension to .TGA
@@ -84,7 +84,7 @@ bool upload_image(const unsigned char* filePath, bool hasalpha)
        Rect natbounds;
        cr = GraphicsImportGetNaturalBounds(gi, &natbounds);
 
-       size_t buffersize = 4 * natbounds.bottom * natbounds.right;
+       //~ size_t buffersize = 4 * natbounds.bottom * natbounds.right;
        //void* buf = malloc(buffersize);
        texture.sizeX=natbounds.right;
        texture.sizeY=natbounds.bottom;
@@ -121,7 +121,7 @@ bool upload_image(const unsigned char* filePath, bool hasalpha)
        GLuint                  bytesPerPixel;                                                                          // Temporary Variable
        bytesPerPixel=texture.bpp/8;
        imageSize = texture.sizeX * texture.sizeY * bytesPerPixel;
-       int alltrans=10;
+       //~ int alltrans=10;
 
        for( GLuint i = 0; i < int( imageSize ); i += 4 )
        {
@@ -133,8 +133,8 @@ bool upload_image(const unsigned char* filePath, bool hasalpha)
                texture.data[i + 3] = temp;
        }
 
-       int tempplace;
-       tempplace=0;
+       //~ int tempplace;
+       //~ tempplace=0;
        if(!hasalpha){
                for( GLuint i = 0; i < int( imageSize ); i += 4 )
                {