X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FOpenGL_Windows.cpp;h=ca05fb75e5a63cbb3a99382e36430106ef92466b;hb=963584c62f5a1ec1f2b505f5c64672b7d4bc7547;hp=5759ddc15fa40d270e876cca271091b7f05df98f;hpb=c0a6dc9211fd7855250be34151a70ec4bceb5126;p=lugaru.git diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 5759ddc..ca05fb7 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -119,15 +119,11 @@ static SDL_Rect *hardcoded_resolutions[] = { unsigned int resolutionDepths[8][2] = {0}; -bool selectDetail(int & width, int & height, int & bpp, int & detail); int closestResolution(int width, int height); int resolutionID(int width, int height); void ReportError (char * strError); -void SetupDSpFullScreen(); -void ShutdownDSp(); - void DrawGL(Game & game); void CreateGLWindow (void); @@ -196,10 +192,7 @@ static void GLAPIENTRY glDeleteTextures_doNothing(GLsizei n, const GLuint *textu void sdlGetCursorPos(POINT *pt) { - int x, y; - SDL_GetMouseState(&x, &y); - pt->x = x; - pt->y = y; + SDL_GetMouseState(&(pt->x), &(pt->y)); } #define GetCursorPos(x) sdlGetCursorPos(x) #define SetCursorPos(x, y) SDL_WarpMouse(x, y) @@ -281,16 +274,6 @@ void ReportError (char * strError) */ } -void SetupDSpFullScreen () -{ -} - - -void ShutdownDSp () -{ -} - - //----------------------------------------------------------------------------------------------------------------------- // OpenGL Drawing @@ -566,74 +549,62 @@ Boolean SetUp (Game & game) DefaultSettings(game); - selectDetail(kContextWidth, kContextHeight, kBitsPerPixel, detail); - + if (!SDL_WasInit(SDL_INIT_VIDEO)) + if (SDL_Init(SDL_INIT_VIDEO) == -1) + { + fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); + return false; + } if(!LoadSettings(game)) { fprintf(stderr, "Failed to load config, creating default\n"); SaveSettings(game); } - if(kBitsPerPixel!=32&&kBitsPerPixel!=16){ kBitsPerPixel=16; } + if (SDL_GL_LoadLibrary(NULL) == -1) + { + fprintf(stderr, "SDL_GL_LoadLibrary() failed: %s\n", SDL_GetError()); + SDL_Quit(); + return false; + } - selectDetail(kContextWidth, kContextHeight, kBitsPerPixel, detail); - - SetupDSpFullScreen(); - - - if (!SDL_WasInit(SDL_INIT_VIDEO)) - { - if (SDL_Init(SDL_INIT_VIDEO) == -1) - { - fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError()); - return false; - } - - if (SDL_GL_LoadLibrary(NULL) == -1) - { - fprintf(stderr, "SDL_GL_LoadLibrary() failed: %s\n", SDL_GetError()); - SDL_Quit(); - return false; - } - - SDL_Rect **res = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL); - if ( (res == NULL) || (res == ((SDL_Rect **)-1)) || (res[0] == NULL) || (res[0]->w < 640) || (res[0]->h < 480) ) - res = hardcoded_resolutions; + SDL_Rect **res = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_OPENGL); + if ( (res == NULL) || (res == ((SDL_Rect **)-1)) || (res[0] == NULL) || (res[0]->w < 640) || (res[0]->h < 480) ) + res = hardcoded_resolutions; - // reverse list (it was sorted biggest to smallest by SDL)... - int count; - for (count = 0; res[count]; count++) - { - if ((res[count]->w < 640) || (res[count]->h < 480)) - break; // sane lower limit. - } + // reverse list (it was sorted biggest to smallest by SDL)... + int count; + for (count = 0; res[count]; count++) + { + if ((res[count]->w < 640) || (res[count]->h < 480)) + break; // sane lower limit. + } - static SDL_Rect *resolutions_block = NULL; - resolutions_block = (SDL_Rect*) realloc(resolutions_block, sizeof (SDL_Rect) * count); - resolutions = (SDL_Rect**) realloc(resolutions, sizeof (SDL_Rect *) * (count + 1)); - if ((resolutions_block == NULL) || (resolutions == NULL)) - { - SDL_Quit(); - fprintf(stderr, "Out of memory!\n"); - return false; - } + static SDL_Rect *resolutions_block = NULL; + resolutions_block = (SDL_Rect*) realloc(resolutions_block, sizeof (SDL_Rect) * count); + resolutions = (SDL_Rect**) realloc(resolutions, sizeof (SDL_Rect *) * (count + 1)); + if ((resolutions_block == NULL) || (resolutions == NULL)) + { + SDL_Quit(); + fprintf(stderr, "Out of memory!\n"); + return false; + } - resolutions[count--] = NULL; - for (int i = 0; count >= 0; i++, count--) - { - memcpy(&resolutions_block[count], res[i], sizeof (SDL_Rect)); - resolutions[count] = &resolutions_block[count]; - } + resolutions[count--] = NULL; + for (int i = 0; count >= 0; i++, count--) + { + memcpy(&resolutions_block[count], res[i], sizeof (SDL_Rect)); + resolutions[count] = &resolutions_block[count]; + } - if (cmdline("showresolutions")) - { - printf("Resolutions we think are okay:\n"); - for (int i = 0; resolutions[i]; i++) - printf(" %d x %d\n", (int) resolutions[i]->w, (int) resolutions[i]->h); - } - } + if (cmdline("showresolutions")) + { + printf("Resolutions we think are okay:\n"); + for (int i = 0; resolutions[i]; i++) + printf(" %d x %d\n", (int) resolutions[i]->w, (int) resolutions[i]->h); + } Uint32 sdlflags = SDL_OPENGL; if (!cmdline("windowed")) @@ -797,9 +768,9 @@ void DoFrameRate (int update) deltaTime /= 1000.0; multiplier=deltaTime; - if(multiplier<.001)multiplier=.001; - if(multiplier>10)multiplier=10; - if(update)frametime = currTime; // reset for next time interval + if(multiplier<.001) multiplier=.001; + if(multiplier>10) multiplier=10; + if(update) frametime = currTime; // reset for next time interval deltaTime = (float) AbsoluteDeltaToDuration (currTime, time); @@ -1118,7 +1089,12 @@ int main(int argc, char **argv) } // game is not in focus, give CPU time to other apps by waiting for messages instead of 'peeking' - STUBBED("give up CPU but sniff the event queue"); + 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; } } @@ -1127,21 +1103,7 @@ int main(int argc, char **argv) pgame = 0; CleanUp (); -// if(game.registernow){ - if(regnow) - { - #if (defined(__APPLE__) && defined(__MACH__)) - launch_web_browser("http://www.wolfire.com/purchase/lugaru/mac"); - #elif PLATFORM_LINUX - launch_web_browser("http://www.wolfire.com/purchase/lugaru/linux"); - #else - launch_web_browser("http://www.wolfire.com/purchase/lugaru/pc"); - #endif - } - #if PLATFORM_LINUX // (this may not be necessary any more.) - _exit(0); // !!! FIXME: hack...crashes on exit! - #endif return 0; } catch (const std::exception& error) @@ -1165,19 +1127,6 @@ int main(int argc, char **argv) // -------------------------------------------------------------------------- - - - bool selectDetail(int & width, int & height, int & bpp, int & detail) - { - bool res = true; - - // currently with SDL, we just use whatever is requested - // and don't care. --ryan. - - - return res; - } - extern int channels[100]; extern OPENAL_SAMPLE * samp[100]; extern OPENAL_STREAM * strm[20]; @@ -1237,25 +1186,15 @@ int main(int argc, char **argv) bool LoadImage(const char * fname, TGAImageRec & tex) { - bool res = true; - if ( tex.data == NULL ) - { return false; - } - - - res = load_image(fname, tex); - - - return res; + else + return load_image(fname, tex); } void ScreenShot(const char * fname) { - save_image(fname); - }