From ae2e35f79294a74e1d3a7ebca2e03019eb6aac69 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Tue, 12 Jul 2022 01:05:29 +0300 Subject: [PATCH] Change renderer initialization point --- src/core.cc | 63 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/src/core.cc b/src/core.cc index b3ea56f..00db56f 100644 --- a/src/core.cc +++ b/src/core.cc @@ -2021,19 +2021,47 @@ int _GNW95_init_window(int width, int height, bool fullscreen) return -1; } - gSdlWindow = SDL_CreateWindow(gProgramWindowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, fullscreen ? SDL_WINDOW_FULLSCREEN : 0); + Uint32 windowFlags = SDL_WINDOW_OPENGL; + + if (fullscreen) { + windowFlags |= SDL_WINDOW_FULLSCREEN; + } + + gSdlWindow = SDL_CreateWindow(gProgramWindowTitle, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, windowFlags); if (gSdlWindow == NULL) { return -1; } + gSdlRenderer = SDL_CreateRenderer(gSdlWindow, -1, 0); + if (gSdlRenderer == NULL) { + goto err; + } + + if (SDL_RenderSetLogicalSize(gSdlRenderer, width, height) != 0) { + goto err; + } + + gSdlTexture = SDL_CreateTexture(gSdlRenderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height); + if (gSdlTexture == NULL) { + goto err; + } + + Uint32 format; + if (SDL_QueryTexture(gSdlTexture, &format, NULL, NULL, NULL) != 0) { + goto err; + } + + gSdlTextureSurface = SDL_CreateRGBSurfaceWithFormat(0, width, height, SDL_BITSPERPIXEL(format), format); + if (gSdlTextureSurface == NULL) { + goto err; + } + #if _WIN32 SDL_SysWMinfo info; SDL_VERSION(&info.version); if (!SDL_GetWindowWMInfo(gSdlWindow, &info)) { - SDL_DestroyWindow(gSdlWindow); - gSdlWindow = NULL; - return -1; + goto err; } // Needed for DirectSound. @@ -2042,6 +2070,23 @@ int _GNW95_init_window(int width, int height, bool fullscreen) } return 0; + +err: + if (gSdlTexture != NULL) { + gSdlTexture = NULL; + } + + if (gSdlRenderer != NULL) { + SDL_DestroyRenderer(gSdlRenderer); + gSdlRenderer = NULL; + } + + if (gSdlWindow != NULL) { + SDL_DestroyWindow(gSdlWindow); + gSdlWindow = NULL; + } + + return -1; } // calculate shift for mask @@ -2093,16 +2138,6 @@ int directDrawInit(int width, int height, int bpp) return 0; } - gSdlRenderer = SDL_CreateRenderer(gSdlWindow, -1, SDL_RENDERER_ACCELERATED); - - SDL_RenderSetLogicalSize(gSdlRenderer, width, height); - - gSdlTexture = SDL_CreateTexture(gSdlRenderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STREAMING, width, height); - - Uint32 format; - SDL_QueryTexture(gSdlTexture, &format, NULL, NULL, NULL); - gSdlTextureSurface = SDL_CreateRGBSurfaceWithFormat(0, width, height, SDL_BITSPERPIXEL(format), format); - gSdlSurface = SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0); if (bpp == 8) {