Mercurial > hg > dmlib
changeset 332:d4802335cbbc
Clean up video (re)initialization.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 15 Oct 2012 13:17:12 +0300 |
parents | c200edce230d |
children | 230cc7c6564d |
files | dmsimple.c |
diffstat | 1 files changed, 21 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/dmsimple.c Mon Oct 15 13:01:28 2012 +0300 +++ b/dmsimple.c Mon Oct 15 13:17:12 2012 +0300 @@ -447,6 +447,23 @@ #endif +BOOL engineInitializeVideo() +{ + dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n", + engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); + + SDL_FreeSurface(engine.screen); + + engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); + if (engine.screen == NULL) + { + dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + return FALSE; + } + return TRUE; +} + + int main(int argc, char *argv[]) { int err; @@ -560,15 +577,9 @@ goto error_exit; } - dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n", - engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); - engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); - if (engine.screen == NULL) - { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); + if (!engineInitializeVideo()) goto error_exit; - } SDL_ShowCursor(SDL_DISABLE); SDL_WM_SetCaption(dmProgDesc, dmProgName); @@ -654,14 +665,9 @@ case SDLK_RETURN: if (engine.event.key.keysym.mod & KMOD_ALT) { - engine.optVFlags ^= SDL_FULLSCREEN; - SDL_FreeSurface(engine.screen); - engine.screen = SDL_SetVideoMode(engine.optScrWidth, engine.optScrHeight, engine.optBitDepth, engine.optVFlags); - if (engine.screen == NULL) - { - dmError("Can't SDL_SetVideoMode(): %s\n", SDL_GetError()); - goto error_exit; - } + engine.optVFlags ^= SDL_FULLSCREEN; + if (!engineInitializeVideo()) + goto error_exit; } break;