X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FOpenGL_Windows.cpp;h=5a5b0f10bc7b8481649b32633c44ef89bc31931c;hb=253b1aa9cfce1e8b1fc12b74d96a7808f615d783;hp=365e48a900e7e9eb37f49e6b8aad2d26952331ca;hpb=d5ff767196019eeb0001f921365bb1e4060eee5b;p=lugaru.git diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 365e48a..5a5b0f1 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -45,6 +45,8 @@ extern "C" { #endif } +using namespace Game; + static bool load_image(const char * fname, TGAImageRec & tex); static bool load_png(const char * fname, TGAImageRec & tex); static bool load_jpg(const char * fname, TGAImageRec & tex); @@ -54,19 +56,11 @@ static bool save_png(const char * fname); #include "openal_wrapper.h" -// ADDED GWC -#ifdef _MSC_VER -#pragma comment(lib, "opengl32.lib") -#pragma comment(lib, "glu32.lib") -#pragma comment(lib, "glaux.lib") -#endif - extern float multiplier; extern float sps; extern float realmultiplier; extern int slomo; extern bool cellophane; -extern float terraindetail; extern float texdetail; extern bool osx; @@ -107,10 +101,8 @@ static SDL_Rect *hardcoded_resolutions[] = { NULL }; -void DrawGL(Game & game); - -Boolean SetUp (Game & game); -void DoUpdate (Game & game); +Boolean SetUp (); +void DoUpdate (); void CleanUp (void); @@ -171,8 +163,6 @@ int kContextHeight; Boolean gDone = false; -Game * pgame = 0; - #ifndef __MINGW32__ static int _argc = 0; static char **_argv = NULL; @@ -196,33 +186,105 @@ bool cmdline(const char *cmd) // OpenGL Drawing -static void sdlEventProc(const SDL_Event &e, Game &game) +void initGL(){ + glClear( GL_COLOR_BUFFER_BIT ); + swap_gl_buffers(); + + // clear all states + glDisable( GL_ALPHA_TEST); + glDisable( GL_BLEND); + glDisable( GL_DEPTH_TEST); + // glDisable( GL_DITHER); + glDisable( GL_FOG); + glDisable( GL_LIGHTING); + glDisable( GL_LOGIC_OP); + glDisable( GL_TEXTURE_1D); + glDisable( GL_TEXTURE_2D); + glPixelTransferi( GL_MAP_COLOR, GL_FALSE); + glPixelTransferi( GL_RED_SCALE, 1); + glPixelTransferi( GL_RED_BIAS, 0); + glPixelTransferi( GL_GREEN_SCALE, 1); + glPixelTransferi( GL_GREEN_BIAS, 0); + glPixelTransferi( GL_BLUE_SCALE, 1); + glPixelTransferi( GL_BLUE_BIAS, 0); + glPixelTransferi( GL_ALPHA_SCALE, 1); + glPixelTransferi( GL_ALPHA_BIAS, 0); + + // set initial rendering states + glShadeModel( GL_SMOOTH); + glClearDepth( 1.0f); + glDepthFunc( GL_LEQUAL); + glDepthMask( GL_TRUE); + // glDepthRange( FRONT_CLIP, BACK_CLIP); + glEnable( GL_DEPTH_TEST); + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + glCullFace( GL_FRONT); + glEnable( GL_CULL_FACE); + glEnable( GL_LIGHTING); +// glEnable( GL_LIGHT_MODEL_AMBIENT); + glEnable( GL_DITHER); + glEnable( GL_COLOR_MATERIAL); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glAlphaFunc( GL_GREATER, 0.5f); + + if ( CanInitStereo(stereomode) ) { + InitStereo(stereomode); + } else { + fprintf(stderr, "Failed to initialize stereo, disabling.\n"); + stereomode = stereoNone; + } +} + +static void toggleFullscreen(){ + 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) { - switch(e.type) - { + switch(e.type) { case SDL_MOUSEMOTION: - game.deltah += e.motion.xrel; - game.deltav += e.motion.yrel; - return; + deltah += e.motion.xrel; + 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) ) { - SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); + (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(); } - return; + break; } } + // -------------------------------------------------------------------------- static Point gMidPoint; -Boolean SetUp (Game & game) +Boolean SetUp () { char string[10]; @@ -231,12 +293,11 @@ Boolean SetUp (Game & game) osx = 0; cellophane=0; texdetail=4; - terraindetail=2; slomospeed=0.25; slomofreq=8012; numplayers=1; - DefaultSettings(game); + DefaultSettings(); if (!SDL_WasInit(SDL_INIT_VIDEO)) if (SDL_Init(SDL_INIT_VIDEO) == -1) @@ -244,9 +305,9 @@ Boolean SetUp (Game & game) fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); return false; } - if(!LoadSettings(game)) { + if(!LoadSettings()) { fprintf(stderr, "Failed to load config, creating default\n"); - SaveSettings(game); + SaveSettings(); } if(kBitsPerPixel!=32&&kBitsPerPixel!=16){ kBitsPerPixel=16; @@ -296,6 +357,7 @@ Boolean SetUp (Game & game) } Uint32 sdlflags = SDL_OPENGL; + if (!cmdline("windowed")) sdlflags |= SDL_FULLSCREEN; @@ -305,6 +367,9 @@ Boolean SetUp (Game & game) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); +#if SDL_VERSION_ATLEAST(1, 2, 10) + SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, vblsync); +#endif if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL) { @@ -343,46 +408,7 @@ Boolean SetUp (Game & game) SDL_WM_GrabInput(SDL_GRAB_ON); - glClear( GL_COLOR_BUFFER_BIT ); - swap_gl_buffers(); - - // clear all states - glDisable( GL_ALPHA_TEST); - glDisable( GL_BLEND); - glDisable( GL_DEPTH_TEST); - // glDisable( GL_DITHER); - glDisable( GL_FOG); - glDisable( GL_LIGHTING); - glDisable( GL_LOGIC_OP); - glDisable( GL_TEXTURE_1D); - glDisable( GL_TEXTURE_2D); - glPixelTransferi( GL_MAP_COLOR, GL_FALSE); - glPixelTransferi( GL_RED_SCALE, 1); - glPixelTransferi( GL_RED_BIAS, 0); - glPixelTransferi( GL_GREEN_SCALE, 1); - glPixelTransferi( GL_GREEN_BIAS, 0); - glPixelTransferi( GL_BLUE_SCALE, 1); - glPixelTransferi( GL_BLUE_BIAS, 0); - glPixelTransferi( GL_ALPHA_SCALE, 1); - glPixelTransferi( GL_ALPHA_BIAS, 0); - - // set initial rendering states - glShadeModel( GL_SMOOTH); - glClearDepth( 1.0f); - glDepthFunc( GL_LEQUAL); - glDepthMask( GL_TRUE); - // glDepthRange( FRONT_CLIP, BACK_CLIP); - glEnable( GL_DEPTH_TEST); - glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glCullFace( GL_FRONT); - glEnable( GL_CULL_FACE); - glEnable( GL_LIGHTING); -// glEnable( GL_LIGHT_MODEL_AMBIENT); - glEnable( GL_DITHER); - glEnable( GL_COLOR_MATERIAL); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glAlphaFunc( GL_GREATER, 0.5f); + initGL(); GLint width = kContextWidth; GLint height = kContextHeight; @@ -391,40 +417,33 @@ Boolean SetUp (Game & game) screenwidth=width; screenheight=height; - game.newdetail=detail; - game.newscreenwidth=screenwidth; - game.newscreenheight=screenheight; - - if ( CanInitStereo(stereomode) ) { - InitStereo(stereomode); - } else { - fprintf(stderr, "Failed to initialize stereo, disabling.\n"); - stereomode = stereoNone; - } + newdetail=detail; + newscreenwidth=screenwidth; + newscreenheight=screenheight; - game.InitGame(); + InitGame(); return true; } -static void DoMouse(Game & game) +static void DoMouse() { - if(mainmenu|| ( (abs(game.deltah)<10*realmultiplier*1000) && (abs(game.deltav)<10*realmultiplier*1000) )) + if(mainmenu|| ( (abs(deltah)<10*realmultiplier*1000) && (abs(deltav)<10*realmultiplier*1000) )) { - game.deltah *= usermousesensitivity; - game.deltav *= usermousesensitivity; - game.mousecoordh += game.deltah; - game.mousecoordv += game.deltav; - if (game.mousecoordh < 0) - game.mousecoordh = 0; - else if (game.mousecoordh >= kContextWidth) - game.mousecoordh = kContextWidth - 1; - if (game.mousecoordv < 0) - game.mousecoordv = 0; - else if (game.mousecoordv >= kContextHeight) - game.mousecoordv = kContextHeight - 1; + deltah *= usermousesensitivity; + deltav *= usermousesensitivity; + mousecoordh += deltah; + mousecoordv += deltav; + if (mousecoordh < 0) + mousecoordh = 0; + else if (mousecoordh >= kContextWidth) + mousecoordh = kContextWidth - 1; + if (mousecoordv < 0) + mousecoordv = 0; + else if (mousecoordv >= kContextHeight) + mousecoordv = kContextHeight - 1; } } @@ -465,7 +484,7 @@ void DoFrameRate (int update) } -void DoUpdate (Game & game) +void DoUpdate () { static float sps=200; static int count; @@ -474,7 +493,7 @@ void DoUpdate (Game & game) DoFrameRate(1); if(multiplier>.6)multiplier=.6; - game.fps=1/multiplier; + fps=1/multiplier; count = multiplier*sps; if(count<2)count=2; @@ -484,22 +503,22 @@ void DoUpdate (Game & game) if(difficulty==1)multiplier*=.9; if(difficulty==0)multiplier*=.8; - if(game.loading==4)multiplier*=.00001; + if(loading==4)multiplier*=.00001; if(slomo&&!mainmenu)multiplier*=slomospeed; oldmult=multiplier; multiplier/=(float)count; - DoMouse(game); + DoMouse(); - game.TickOnce(); + TickOnce(); for(int i=0;i