From 7b551ba4fbe64d05ef044b1a6bc6f434878de942 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 7 Oct 2013 10:06:09 +0000 Subject: [PATCH] Fix OpenGL under SDL && Windows. (Almost. SDL 1.2 works fine, but SDL2 has an unresolved problem where OpenGL screen updates flicker over a black background.) git-svn-id: https://svn.eduke32.com/eduke32@4088 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/glbuild.c | 40 ++++++++++++++++++----------- polymer/eduke32/build/src/sdlayer.c | 10 ++++++++ 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/polymer/eduke32/build/src/glbuild.c b/polymer/eduke32/build/src/glbuild.c index c04c1cc2c..8568c7ebd 100644 --- a/polymer/eduke32/build/src/glbuild.c +++ b/polymer/eduke32/build/src/glbuild.c @@ -294,11 +294,17 @@ bwglGetPixelFormatProcPtr bwglGetPixelFormat; bwglSetPixelFormatProcPtr bwglSetPixelFormat; bwglSwapIntervalEXTProcPtr bwglSwapIntervalEXT; bwglCreateContextAttribsARBProcPtr bwglCreateContextAttribsARB; - -static HMODULE hGLDLL, hGLUDLL; #else #include +#endif +#if !defined RENDERTYPESDL && defined _WIN32 +static HMODULE hGLDLL; +#endif + +#if defined _WIN32 +static HMODULE hGLUDLL; +#else static void *gluhandle = NULL; #endif @@ -332,7 +338,7 @@ int32_t loadgldriver(const char *driver) { int32_t err=0; -#ifdef _WIN32 +#if !defined RENDERTYPESDL && defined _WIN32 if (hGLDLL) return 0; #endif @@ -348,10 +354,18 @@ int32_t loadgldriver(const char *driver) } #if defined RENDERTYPESDL - if (SDL_GL_LoadLibrary(driver)) goto fail; + if (SDL_GL_LoadLibrary(driver)) + { + initprintf("Failed loading \"%s\": %s\n", driver, SDL_GetError()); + return -1; + } #elif defined _WIN32 hGLDLL = LoadLibrary(driver); - if (!hGLDLL) goto fail; + if (!hGLDLL) + { + initprintf("Failed loading \"%s\"\n", driver); + return -1; + } #endif gldriver = Bstrdup(driver); @@ -485,16 +499,12 @@ int32_t loadgldriver(const char *driver) if (err) unloadgldriver(); return err; - -fail: - initprintf("Failed loading \"%s\"\n",driver); - return -1; } int32_t loadglextensions(void) { int32_t err = 0; -#ifdef _WIN32 +#if !defined RENDERTYPESDL && defined _WIN32 if (!hGLDLL) return 0; #endif @@ -648,14 +658,14 @@ int32_t unloadgldriver(void) { unloadglulibrary(); -#ifdef _WIN32 +#if !defined RENDERTYPESDL && defined _WIN32 if (!hGLDLL) return 0; #endif Bfree(gldriver); gldriver = NULL; -#ifdef _WIN32 +#if !defined RENDERTYPESDL && defined _WIN32 FreeLibrary(hGLDLL); hGLDLL = NULL; #endif @@ -938,7 +948,7 @@ int32_t loadglulibrary(const char *driver) { int32_t err=0; -#ifdef _WIN32 +#if defined _WIN32 if (hGLUDLL) return 0; #endif @@ -990,14 +1000,14 @@ fail: int32_t unloadglulibrary(void) { -#ifdef _WIN32 +#if defined _WIN32 if (!hGLUDLL) return 0; #endif Bfree(glulibrary); glulibrary = NULL; -#ifdef _WIN32 +#if defined _WIN32 FreeLibrary(hGLUDLL); hGLUDLL = NULL; #else diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 27721df06..37ae0810b 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -1256,6 +1256,10 @@ static int32_t create_window_and_renderer(int32_t x, int32_t y, int32_t c, int32 destroy_window_and_renderer(); return -1; } + +#ifdef _WIN32 + loadglextensions(); +#endif } sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, x, y); @@ -1409,6 +1413,9 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) initprintf("Unable to set video mode!\n"); return -1; } +#ifdef _WIN32 + loadglextensions(); +#endif # else destroy_window_and_renderer(); @@ -1431,6 +1438,9 @@ int32_t setvideomode(int32_t x, int32_t y, int32_t c, int32_t fs) initprintf("Unable to set video mode!\n"); return -1; } +#ifdef _WIN32 + loadglextensions(); +#endif sdl_buffersurface = SDL_CreateRGBSurface(SURFACE_FLAGS, x, y, c, 0, 0, 0, 0); if (!sdl_buffersurface) {