# SDL-1.2: atari:video: remove OpenGL LDG support

**URL:** <https://discourse.libsdl.org/t/sdl-1-2-atari-remove-opengl-ldg-support/69387>\
**Category:** SDL Commits\
**Created:** [September 24, 2026, 1:34pm UTC](https://discourse.libsdl.org/t/sdl-1-2-atari-remove-opengl-ldg-support/69387 "2026-09-24T13:34:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [September 24, 2026, 1:34pm UTC](https://discourse.libsdl.org/t/sdl-1-2-atari-remove-opengl-ldg-support/69387/1 "2026-09-24T13:34:26Z")

</div>

> **[atari:video: remove OpenGL LDG support · libsdl-org/SDL-1.2@b90479c](https://github.com/libsdl-org/SDL-1.2/commit/b90479c71b3e328467052849107bc76f127a80a9)**
>
> LDG has several design flaws (esp. in a multitasking environment) and
> http://ldg.lutece.net has been basically abandoned:
> 
> \- MesaGL 2.5 LDG was last updated in 2000
> 
> \- TinyGL LDG was last updated i...

```diff
From b90479c71b3e328467052849107bc76f127a80a9 Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Thu, 24 Sep 2026 12:16:23 +1000
Subject: [PATCH] atari:video: remove OpenGL LDG support

LDG has several design flaws (esp. in a multitasking environment) and
http://ldg.lutece.net has been basically abandoned:

- MesaGL 2.5 LDG was last updated in 2000

- TinyGL LDG was last updated in 2005

- MesaGL 6.2 LDG
  (https://pmandin.atari.org/en/index.php?post/2008/08/19/117-en-ports-libs-mesa)
  was last pdated in 2004

Dynamic library support via LDG stays for now.
---
 README.MiNT | 20 +-
 configure | 117 +---
 configure.ac | 29 +-
 include/SDL_config.h.in | 1 -
 src/video/ataricommon/SDL_atarigl.c | 929 ++++----------------------
 src/video/ataricommon/SDL_atarigl_c.h | 39 +-
 src/video/gem/SDL_gemvideo.c | 6 +-
 src/video/xbios/SDL_xbios.c | 6 +-
 8 files changed, 152 insertions(+), 995 deletions(-)

diff --git a/README.MiNT b/README.MiNT
index 76cf44ac7..a175edef0 100644
--- a/README.MiNT
+++ b/README.MiNT
@@ -75,9 +75,6 @@ SDL_VIDEODRIVER:
 	Set to 'xbios' to force xbios video driver. Uses XBIOS/Ikbd events driver.
 	Set to 'gem' to force gem video driver. Uses an internal events driver.
 
-SDL_VIDEO_GL_DRIVER:
-	Set to filename to load as OpenGL library, if you use SDL_GL_LoadLibrary()
-
 SDL_VIDEO_ALIGNED_WINDOWS:
 	Set to force aligning of the window's x coordinate to a 16-pixel boundary
 	(e.g. for speed reasons)
@@ -135,19 +132,10 @@ SDL_JOYSTICK_ATARI:
 VI. More informations about drivers:
 
 OpenGL:
-	The default is to use the Mesa offscreen driver (osmesa.ldg). If you want
-	to use an older OpenGL implementation, like mesa_gl.ldg or tiny_gl.ldg,
-	your program must use SDL_GL_LoadLibrary() to do so, and retrieve the
-	needed function pointers with SDL_LoadFunction(). In all cases, the OpenGL
-	context is taken care of by SDL itself, you just have to use gl* functions.
-
-	However, there is one OpenGL call that has a different prototype in the old
-	implementations: glOrtho(). In the old implementations, it has 6 float as
-	parameters, in the standard one, it has 6 double parameters. If you want
-	to compile testdyngl, or any other SDL program that loads its OpenGL
-	library, you must change the glOrtho() prototype used in this program. In
-	osmesa.ldg, you can retrieve a glOrtho() with double parameters, by
-	searching for the function "glOrtho6d".
+	OpenGL is provided by a statically linked OSMesa (libOSMesa.a), the
+	OpenGL context is taken care of by SDL itself, you just have to use gl*
+	functions. Programs not calling any gl* function don't link OSMesa at all.
+	SDL_GL_LoadLibrary() accepts only NULL, i.e. the linked OSMesa.
 
 Xbios video:
 	Video chip is detected using the _VDO cookie.
diff --git a/configure b/configure
index 991ec623c..590092e1e 100755
--- a/configure
+++ b/configure
@@ -790,7 +790,6 @@ SDL_STATIC_LIBS
 SDL_LIBS
 SDL_CFLAGS
 PTH_CONFIG
-OSMESA_CONFIG
 CACACONFIG
 DIRECTFB_LIBS
 DIRECTFB_CFLAGS
@@ -990,7 +989,6 @@ enable_xbios
 enable_gem
 enable_video_dummy
 enable_video_opengl
-enable_osmesa_shared
 enable_screensaver
 enable_input_events
 enable_input_tslib
@@ -1724,7 +1722,6 @@ Optional Features:
   --enable-video-gem use Atari Gem video driver [default=yes]
   --enable-video-dummy use dummy video driver [default=yes]
   --enable-video-opengl include OpenGL context creation [default=yes]
- --enable-osmesa-shared dynamically load OSMesa OpenGL support [default=yes]
   --enable-screensaver enable screensaver by default while any SDL
                           application is running [default=no]
   --enable-input-events use Linux 2.4 unified input interface [default=yes]
@@ -4839,13 +4836,13 @@ if ${lt_cv_nm_interface+:} false; then :
 else
   lt_cv_nm_interface="BSD nm"
   echo "int some_variable = 0;" > conftest.$ac_ext
- (eval echo "\"\$as_me:4842: $ac_compile\"" >&5)
+ (eval echo "\"\$as_me:4839: $ac_compile\"" >&5)
   (eval "$ac_compile" 2>conftest.err)
   cat conftest.err >&5
- (eval echo "\"\$as_me:4845: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
+ (eval echo "\"\$as_me:4842: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
   (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
   cat conftest.err >&5
- (eval echo "\"\$as_me:4848: output\"" >&5)
+ (eval echo "\"\$as_me:4845: output\"" >&5)
   cat conftest.out >&5
   if $GREP 'External.*some_variable' conftest.out > /dev/null; then
     lt_cv_nm_interface="MS dumpbin"
@@ -6058,7 +6055,7 @@ ia64-*-hpux*)
   ;;
 *-*-irix6*)
   # Find out which ABI we are using.
- echo '#line 6061 "configure"' > conftest.$ac_ext
+ echo '#line 6058 "configure"' > conftest.$ac_ext
   if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -7653,11 +7650,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:7656: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:7653: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
- echo "$as_me:7660: \$? = $ac_status" >&5
+ echo "$as_me:7657: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -8002,11 +7999,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:8005: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:8002: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
- echo "$as_me:8009: \$? = $ac_status" >&5
+ echo "$as_me:8006: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -8107,11 +8104,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:8110: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:8107: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
- echo "$as_me:8114: \$? = $ac_status" >&5
+ echo "$as_me:8111: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -8162,11 +8159,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:8165: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:8162: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
- echo "$as_me:8169: \$? = $ac_status" >&5
+ echo "$as_me:8166: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -10595,7 +10592,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10598 "configure"
+#line 10595 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -10691,7 +10688,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 10694 "configure"
+#line 10691 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -14141,11 +14138,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:14144: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:14141: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
- echo "$as_me:14148: \$? = $ac_status" >&5
+ echo "$as_me:14145: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -14240,11 +14237,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:14243: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:14240: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
- echo "$as_me:14247: \$? = $ac_status" >&5
+ echo "$as_me:14244: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -14292,11 +14289,11 @@ else
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:14295: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:14292: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
- echo "$as_me:14299: \$? = $ac_status" >&5
+ echo "$as_me:14296: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -20564,78 +20561,12 @@ else
 fi
 
 
- # Static linking to -lOSMesa
- # Extract the first word of "osmesa-config", so it can be a program name with args.
-set dummy osmesa-config; ac_word=$2
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-$as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_OSMESA_CONFIG+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- case $OSMESA_CONFIG in
- [\\/]* | ?:[\\/]*)
- ac_cv_path_OSMESA_CONFIG="$OSMESA_CONFIG" # Let the user override the test with a path.
- ;;
- *)
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
-do
- IFS=$as_save_IFS
- test -z "$as_dir" && as_dir=.
- for ac_exec_ext in '' $ac_executable_extensions; do
- if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
- ac_cv_path_OSMESA_CONFIG="$as_dir/$ac_word$ac_exec_ext"
- $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
- break 2
- fi
-done
- done
-IFS=$as_save_IFS
-
- test -z "$ac_cv_path_OSMESA_CONFIG" && ac_cv_path_OSMESA_CONFIG="no"
- ;;
-esac
-fi
-OSMESA_CONFIG=$ac_cv_path_OSMESA_CONFIG
-if test -n "$OSMESA_CONFIG"; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OSMESA_CONFIG" >&5
-$as_echo "$OSMESA_CONFIG" >&6; }
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-fi
-
-
- if test "x$OSMESA_CONFIG" = "xno" -o "x$enable_atari_ldg" = "xno"; then
- # -lOSMesa is really the static library
- if test "x$have_osmesa_hdr" = "xyes" -a "x$have_osmesa_lib" = "xyes"; then
- OSMESA_LIBS="-lOSMesa"
- fi
- else
- # -lOSMesa is a loader for OSMesa.ldg
- OSMESA_CFLAGS=`$OSMESA_CONFIG --cflags`
- OSMESA_LIBS=`$OSMESA_CONFIG --libs`
- fi
- $as_echo "#define SDL_VIDEO_OPENGL 1" >>confdefs.h
-
- $as_echo "#define SDL_VIDEO_OPENGL_OSMESA 1" >>confdefs.h
-
- SDL_CFLAGS="$SDL_CFLAGS $OSMESA_CFLAGS"
- SDL_LIBS="$SDL_LIBS $OSMESA_LIBS"
-
- # Check whether --enable-osmesa-shared was given.
-if test "${enable_osmesa_shared+set}" = set; then :
- enableval=$enable_osmesa_shared;
-else
- enable_osmesa_shared=yes
-fi
+ if test "x$have_osmesa_hdr" = "xyes" -a "x$have_osmesa_lib" = "xyes"; then
+ $as_echo "#define SDL_VIDEO_OPENGL 1" >>confdefs.h
 
- if test "x$enable_osmesa_shared" = "xyes" -a "x$enable_atari_ldg" = "xyes"; then
- # Dynamic linking
- if test "x$have_osmesa_hdr" = "xyes"; then
- $as_echo "#define SDL_VIDEO_OPENGL_OSMESA_DYNAMIC 1" >>confdefs.h
+ $as_echo "#define SDL_VIDEO_OPENGL_OSMESA 1" >>confdefs.h
 
- fi
+ SDL_LIBS="$SDL_LIBS -lOSMesa"
         fi
     fi
 }
diff --git a/configure.ac b/configure.ac
index ddbd40711..c21a2f4f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1768,31 +1768,10 @@ CheckAtariOSMesa()
         AC_CHECK_HEADER(GL/osmesa.h, have_osmesa_hdr=yes)
         AC_CHECK_LIB(OSMesa, OSMesaCreateContext, have_osmesa_lib=yes, have_osmesa_lib=no, -lm)
 
- # Static linking to -lOSMesa
- AC_PATH_PROG(OSMESA_CONFIG, osmesa-config, no)
- if test "x$OSMESA_CONFIG" = "xno" -o "x$enable_atari_ldg" = "xno"; then
- # -lOSMesa is really the static library
- if test "x$have_osmesa_hdr" = "xyes" -a "x$have_osmesa_lib" = "xyes"; then
- OSMESA_LIBS="-lOSMesa"
- fi
- else
- # -lOSMesa is a loader for OSMesa.ldg
- OSMESA_CFLAGS=`$OSMESA_CONFIG --cflags`
- OSMESA_LIBS=`$OSMESA_CONFIG --libs`
- fi
- AC_DEFINE(SDL_VIDEO_OPENGL)
- AC_DEFINE(SDL_VIDEO_OPENGL_OSMESA)
- SDL_CFLAGS="$SDL_CFLAGS $OSMESA_CFLAGS"
- SDL_LIBS="$SDL_LIBS $OSMESA_LIBS"
-
- AC_ARG_ENABLE(osmesa-shared,
-[AS_HELP_STRING([--enable-osmesa-shared], [dynamically load OSMesa OpenGL support [default=yes]])],
- , enable_osmesa_shared=yes)
- if test "x$enable_osmesa_shared" = "xyes" -a "x$enable_atari_ldg" = "xyes"; then
- # Dynamic linking
- if test "x$have_osmesa_hdr" = "xyes"; then
- AC_DEFINE(SDL_VIDEO_OPENGL_OSMESA_DYNAMIC)
- fi
+ if test "x$have_osmesa_hdr" = "xyes" -a "x$have_osmesa_lib" = "xyes"; then
+ AC_DEFINE(SDL_VIDEO_OPENGL)
+ AC_DEFINE(SDL_VIDEO_OPENGL_OSMESA)
+ SDL_LIBS="$SDL_LIBS -lOSMesa"
         fi
     fi
 }
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index c118912cd..bc55a4d62 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -307,7 +307,6 @@
 #undef SDL_VIDEO_OPENGL_GLX
 #undef SDL_VIDEO_OPENGL_WGL
 #undef SDL_VIDEO_OPENGL_OSMESA
-#undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC
 
 /* Disable screensaver */
 #undef SDL_VIDEO_DISABLE_SCREENSAVER
diff --git a/src/video/ataricommon/SDL_atarigl.c b/src/video/ataricommon/SDL_atarigl.c
index 46c4fae10..dfcfe619c 100644
--- a/src/video/ataricommon/SDL_atarigl.c
+++ b/src/video/ataricommon/SDL_atarigl.c
@@ -21,7 +21,7 @@
 */
 #include "SDL_config.h"
 
-/* Atari OSMesa.ldg implementation of SDL OpenGL support */
+/* Atari OSMesa implementation of SDL OpenGL support */
 
 /*--- Includes ---*/
 
@@ -36,51 +36,20 @@
 #pragma weak OSMesaGetProcAddress
 #pragma weak glGetIntegerv
 #pragma weak glFinish
-#pragma weak glFlush
 #endif
 
-#include <mint/osbind.h>
-
 #include "SDL_endian.h"
 #include "SDL_video.h"
 #include "SDL_atarigl_c.h"
-#if SDL_VIDEO_OPENGL_OSMESA_DYNAMIC
-#include "SDL_loadso.h"
-#endif
-
-/*--- Defines ---*/
-
-#define PATH_OSMESA_LDG	"osmesa.ldg"
-#define PATH_MESAGL_LDG	"mesa_gl.ldg"
-#define PATH_TINYGL_LDG	"tiny_gl.ldg"
-
-#define VDI_RGB	0xf
 
 /*--- Functions prototypes ---*/
 
 #if SDL_VIDEO_OPENGL
-static void SDL_AtariGL_UnloadLibrary(_THIS);
-
-static void CopyShadowNull(_THIS, SDL_Surface *surface);
-static void CopyShadowDirect(_THIS, SDL_Surface *surface);
-static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface);
-static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface);
-static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface);
-static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface);
-static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface);
-static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface);
-static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface);
-static void CopyShadow8888To555(_THIS, SDL_Surface *surface);
-static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
-
 static void ConvertNull(_THIS, SDL_Surface *surface);
 static void Convert565To555be(_THIS, SDL_Surface *surface);
 static void Convert565To555le(_THIS, SDL_Surface *surface);
 static void Convert565le(_THIS, SDL_Surface *surface);
 static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface);
-
-static int InitNew(_THIS, SDL_Surface *current);
-static int InitOld(_THIS, SDL_Surface *current);
 #endif
 
 /*--- Public functions ---*/
@@ -88,343 +57,15 @@ static int InitOld(_THIS, SDL_Surface *current);
 int SDL_AtariGL_Init(_THIS, SDL_Surface *current)
 {
 #if SDL_VIDEO_OPENGL
-	if (gl_oldmesa) {
- gl_active = InitOld(this, current);		
-	} else {
- gl_active = InitNew(this, current);		
-	}
-#endif
-
-	return (gl_active);
-}
-
-void SDL_AtariGL_Quit(_THIS, SDL_bool unload)
-{
-#if SDL_VIDEO_OPENGL
-	if (gl_oldmesa) {
- /* Old mesa implementations */
- if (this->gl_data->OSMesaDestroyLDG) {
- this->gl_data->OSMesaDestroyLDG();
- }
- if (gl_shadow) {
- Mfree(gl_shadow);
- gl_shadow = NULL;
- }
-	} else {
- /* New mesa implementation */
- if (gl_ctx) {
- if (this->gl_data->OSMesaDestroyContext) {
- this->gl_data->OSMesaDestroyContext(gl_ctx);
- }
- gl_ctx = NULL;
- }
-	}
-
-	if (unload) {
- SDL_AtariGL_UnloadLibrary(this);
-	}
-
-#endif /* SDL_VIDEO_OPENGL */
-	gl_active = 0;
-}
-
-int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
-{
-#if SDL_VIDEO_OPENGL
-
-#if SDL_VIDEO_OPENGL_OSMESA_DYNAMIC
-	void *handle;
-	SDL_bool cancel_load;
-
-	if (gl_active) {
- SDL_SetError("OpenGL context already created");
- return -1;
-	}
-
-	/* Unload previous driver */
-	SDL_AtariGL_UnloadLibrary(this);
-
-	/* Load library given by path */
-	handle = SDL_LoadObject(path);
-	if (handle == NULL) {
- /* Try to load another one */
- path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
- if ( path != NULL ) {
- handle = SDL_LoadObject(path);
- }
-
- /* If it does not work, try some other */
- if (handle == NULL) {
- path = PATH_OSMESA_LDG;
- handle = SDL_LoadObject(path);
- }
-
- if (handle == NULL) {
- path = PATH_MESAGL_LDG;
- handle = SDL_LoadObject(path);
- }
-
- if (handle == NULL) {
- path = PATH_TINYGL_LDG;
- handle = SDL_LoadObject(path);
- }
-	}
-
-	if (handle == NULL) {
- SDL_SetError("Could not load OpenGL library");
- return -1;
-	}
-
-	this->gl_data->glGetIntegerv = SDL_LoadFunction(handle, "glGetIntegerv");
-	this->gl_data->glFinish = SDL_LoadFunction(handle, "glFinish");
-	this->gl_data->glFlush = SDL_LoadFunction(handle, "glFlush");
-
-	cancel_load = SDL_FALSE;
-	if (this->gl_data->glGetIntegerv == NULL) {
- cancel_load = SDL_TRUE;
-	} else {
- /* We need either glFinish (OSMesa) or glFlush (TinyGL) */
- if ((this->gl_data->glFinish == NULL) &&
- (this->gl_data->glFlush == NULL)) {
- cancel_load = SDL_TRUE;
- }
-	}
-	if (cancel_load) {
- SDL_SetError("Could not retrieve OpenGL functions");
- SDL_UnloadObject(handle);
- /* Restore pointers to static library */
- SDL_AtariGL_InitPointers(this);
- return -1;
-	}
-
-	/* Load functions pointers (osmesa.ldg) */
-	this->gl_data->OSMesaCreateContextExt = SDL_LoadFunction(handle, "OSMesaCreateContextExt");
-	this->gl_data->OSMesaDestroyContext = SDL_LoadFunction(handle, "OSMesaDestroyContext");
-	this->gl_data->OSMesaMakeCurrent = SDL_LoadFunction(handle, "OSMesaMakeCurrent");
-	this->gl_data->OSMesaPixelStore = SDL_LoadFunction(handle, "OSMesaPixelStore");
-	this->gl_data->OSMesaGetProcAddress = SDL_LoadFunction(handle, "OSMesaGetProcAddress");
-
-	/* Load old functions pointers (mesa_gl.ldg, tiny_gl.ldg) */
-	this->gl_data->OSMesaCreateLDG = SDL_LoadFunction(handle, "OSMesaCreateLDG");
-	this->gl_data->OSMesaDestroyLDG = SDL_LoadFunction(handle, "OSMesaDestroyLDG");
-
-	gl_oldmesa = 0;
-
-	if ( (this->gl_data->OSMesaCreateContextExt == NULL) || 
- (this->gl_data->OSMesaDestroyContext == NULL) ||
- (this->gl_data->OSMesaMakeCurrent == NULL) ||
- (this->gl_data->OSMesaPixelStore == NULL) ||
- (this->gl_data->OSMesaGetProcAddress == NULL)) {
- /* Hum, maybe old library ? */
- if ( (this->gl_data->OSMesaCreateLDG == NULL) || 
- (this->gl_data->OSMesaDestroyLDG == NULL)) {
- SDL_SetError("Could not retrieve OSMesa functions");
- SDL_UnloadObject(handle);
- /* Restore pointers to static library */
- SDL_AtariGL_InitPointers(this);
- return -1;
- } else {
- gl_oldmesa = 1;
- }
-	}
-
-	this->gl_config.dll_handle = handle;
-	if ( path ) {
- SDL_strlcpy(this->gl_config.driver_path, path,
- SDL_arraysize(this->gl_config.driver_path));
-	} else {
- *this->gl_config.driver_path = '\0';
-	}
-
-#endif
-	this->gl_config.driver_loaded = 1;
-
-	return 0;
-#else
-	return -1;
-#endif
-}
-
-void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc)
-{
-	void *func = NULL;
-#if SDL_VIDEO_OPENGL
-
-	if (this->gl_config.dll_handle) {
- func = SDL_LoadFunction(this->gl_config.dll_handle, (void *)proc);
-	} else if (this->gl_data->OSMesaGetProcAddress) {
- func = this->gl_data->OSMesaGetProcAddress(proc);
-	}
-
-#endif
-	return func;
-}
-
-int SDL_AtariGL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
-{
-#if SDL_VIDEO_OPENGL
-	GLenum mesa_attrib;
-	SDL_Surface *surface;
-
-	if (!gl_active) {
- return -1;
-	}
-
-	switch(attrib) {
- case SDL_GL_RED_SIZE:
- mesa_attrib = GL_RED_BITS;
- break;
- case SDL_GL_GREEN_SIZE:
- mesa_attrib = GL_GREEN_BITS;
- break;
- case SDL_GL_BLUE_SIZE:
- mesa_attrib = GL_BLUE_BITS;
- break;
- case SDL_GL_ALPHA_SIZE:
- mesa_attrib = GL_ALPHA_BITS;
- break;
- case SDL_GL_DOUBLEBUFFER:
- surface = this->screen;
- *value = ((surface->flags & SDL_DOUBLEBUF)==SDL_DOUBLEBUF);
- return 0;
- case SDL_GL_DEPTH_SIZE:
- mesa_attrib = GL_DEPTH_BITS;
- break;
- case SDL_GL_STENCIL_SIZE:
- mesa_attrib = GL_STENCIL_BITS;
- break;
- case SDL_GL_ACCUM_RED_SIZE:
- mesa_attrib = GL_ACCUM_RED_BITS;
- break;
- case SDL_GL_ACCUM_GREEN_SIZE:
- mesa_attrib = GL_ACCUM_GREEN_BITS;
- break;
- case SDL_GL_ACCUM_BLUE_SIZE:
- mesa_attrib = GL_ACCUM_BLUE_BITS;
- break;
- case SDL_GL_ACCUM_ALPHA_SIZE:
- mesa_attrib = GL_ACCUM_ALPHA_BITS;
- break;
- default :
- return -1;
-	}
-
-	this->gl_data->glGetIntegerv(mesa_attrib, value);
-	return 0;
-#else
-	return -1;
-#endif
-}
-
-int SDL_AtariGL_MakeCurrent(_THIS)
-{
-#if SDL_VIDEO_OPENGL
-	SDL_Surface *surface;
-	GLenum type;
-
-	if (gl_oldmesa && gl_active) {
- return 0;
-	}
-
-	if (this->gl_config.dll_handle) {
- if ((this->gl_data->OSMesaMakeCurrent == NULL) ||
- (this->gl_data->OSMesaPixelStore == NULL)) {
- return -1;
- }
-	}
-
-	if (!gl_active) {
- SDL_SetError("Invalid OpenGL context");
- return -1;
-	}
-
-	surface = this->screen;
-	
-	if ((surface->format->BitsPerPixel == 15) || (surface->format->BitsPerPixel == 16)) {
- type = GL_UNSIGNED_SHORT_5_6_5;
-	} else {
- type = GL_UNSIGNED_BYTE;
-	}
-
-	if (!(this->gl_data->OSMesaMakeCurrent(gl_ctx, (Uint8 *)surface->pixels + surface->offset, type, surface->w, surface->h))) {
- SDL_SetError("Can not make OpenGL context current");
- return -1;
-	}
-
-	/* OSMesa draws upside down */
-	this->gl_data->OSMesaPixelStore(OSMESA_Y_UP, 0);
-
-	/* The surface can be a part of a larger buffer */
-	this->gl_data->OSMesaPixelStore(OSMESA_ROW_LENGTH, surface->pitch / gl_pixelsize);
-
-	return 0;
-#else
-	return -1;
-#endif
-}
-
-void SDL_AtariGL_SwapBuffers(_THIS)
-{
-#if SDL_VIDEO_OPENGL
-	if (gl_active) {
- if (this->gl_config.dll_handle) {
- if (this->gl_data->glFinish) {
- this->gl_data->glFinish();
- } else if (this->gl_data->glFlush) {
- this->gl_data->glFlush();
- }
- } else {
- this->gl_data->glFinish();
- }
- gl_copyshadow(this, this->screen);
- gl_convert(this, this->screen);
-	}
-#endif
-}
-
-void SDL_AtariGL_InitPointers(_THIS)
-{
-#if SDL_VIDEO_OPENGL
-	this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
-	this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
-	this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
-	this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
-	this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
-
-	this->gl_data->glGetIntegerv = glGetIntegerv;
-	this->gl_data->glFinish = glFinish;
-	this->gl_data->glFlush = glFlush;
-
-	this->gl_data->OSMesaCreateLDG = NULL;
-	this->gl_data->OSMesaDestroyLDG = NULL;
-#endif
-}
-
-/*--- Private functions ---*/
-
-#if SDL_VIDEO_OPENGL
-static void SDL_AtariGL_UnloadLibrary(_THIS)
-{
-	if (this->gl_config.dll_handle) {
- SDL_UnloadObject(this->gl_config.dll_handle);
- this->gl_config.dll_handle = NULL;
-
- /* Restore pointers to static library */
- SDL_AtariGL_InitPointers(this);
-	}
-}
-
-/*--- Creation of an OpenGL context using new/old functions ---*/
-
-static int InitNew(_THIS, SDL_Surface *current)
-{
 	GLenum osmesa_format;
 	SDL_PixelFormat *pixel_format;
 	Uint32	redmask;
 	int recreatecontext;
 	GLint newaccumsize;
 
-	if (this->gl_data->OSMesaCreateContextExt == NULL) {
+	gl_active = 0;
+
+	if (OSMesaCreateContextExt == NULL) {
 		return 0;
 	}
 
@@ -433,8 +74,6 @@ static int InitNew(_THIS, SDL_Surface *current)
 
 	/* Init OpenGL context using OSMesa */
 	gl_convert = ConvertNull;
-	gl_copyshadow = CopyShadowNull;
-	gl_upsidedown = SDL_FALSE;
 
 	pixel_format = current->format;
 	redmask = pixel_format->Rmask;
@@ -502,9 +141,9 @@ static int InitNew(_THIS, SDL_Surface *current)
 		recreatecontext = 0;
 	}
 	if (recreatecontext) {
- SDL_AtariGL_Quit(this, SDL_FALSE);
+ SDL_AtariGL_Quit(this);
 
- gl_ctx = this->gl_data->OSMesaCreateContextExt(
+ gl_ctx = OSMesaCreateContextExt(
 			osmesa_format, this->gl_config.depth_size,
 			this->gl_config.stencil_size, newaccumsize, NULL );
 
@@ -521,498 +160,160 @@ static int InitNew(_THIS, SDL_Surface *current)
 		}
 	}
 
-	return (gl_ctx != NULL);
-}
-
-
-static int InitOld(_THIS, SDL_Surface *current)
-{
-	GLenum osmesa_format;
-	SDL_PixelFormat *pixel_format;
-	Uint32	redmask;
-	int recreatecontext, tinygl_present;
-
-	if (this->gl_config.dll_handle) {
- if (this->gl_data->OSMesaCreateLDG == NULL) {
- return 0;
- }
-	}
-
-	/* TinyGL only supports VDI_RGB (OSMESA_RGB) */
-	tinygl_present=0;
-	if (this->gl_config.dll_handle) {
- if (this->gl_data->glFinish == NULL) {
- tinygl_present=1;
- }
-	}
-
-	/* Init OpenGL context using OSMesa */
-	gl_convert = ConvertNull;
-	gl_copyshadow = CopyShadowNull;
-	gl_upsidedown = SDL_FALSE;
-
-	pixel_format = current->format;
-	redmask = pixel_format->Rmask;
-	switch (pixel_format->BitsPerPixel) {
- case 15:
- /* 15 bits unsupported */
- if (tinygl_present) {
- gl_pixelsize = 3;
- osmesa_format = VDI_RGB;
- if (redmask == 31<<10) {
- gl_copyshadow = CopyShadowRGBTo555;
- } else {
- gl_copyshadow = CopyShadowRGBTo565;
- gl_convert = Convert565To555le;
- }
- } else {
- gl_pixelsize = 4;
- gl_upsidedown = SDL_TRUE;
- osmesa_format = OSMESA_ARGB;
- if (redmask == 31<<10) {
- gl_copyshadow = CopyShadow8888To555;
- } else {
- gl_copyshadow = CopyShadow8888To565;
- gl_convert = Convert565To555le;
- }
- }
- break;
- case 16:
- /* 16 bits unsupported */
- if (tinygl_present) {
- gl_pixelsize = 3;
- osmesa_format = VDI_RGB;
- gl_copyshadow = CopyShadowRGBTo565;
- if (redmask != 31<<11) {
- /* 565, little endian, unsupported */
- gl_convert = Convert565le;
- }
- } else {
- gl_pixelsize = 4;
- gl_upsidedown = SDL_TRUE;
- osmesa_format = OSMESA_ARGB;
- gl_copyshadow = CopyShadow8888To565;
- if (redmask != 31<<11) {
- /* 565, little endian, unsupported */
- gl_convert = Convert565le;
- }
- }
- break;
- case 24:
- gl_pixelsize = 3;
- if (tinygl_present) {
- osmesa_format = VDI_RGB;
- gl_copyshadow = CopyShadowDirect;
- if (redmask != 255<<16) {
- gl_copyshadow = CopyShadowRGBSwap;
- }
- } else {
- gl_copyshadow = CopyShadowDirect;
- gl_upsidedown = SDL_TRUE;
- if (redmask == 255<<16) {
- osmesa_format = OSMESA_RGB;
- } else {
- osmesa_format = OSMESA_BGR;
- }
- }
- break;
- case 32:
- if (tinygl_present) {
- gl_pixelsize = 3;
- osmesa_format = VDI_RGB;
- gl_copyshadow = CopyShadowRGBToARGB;
- if (redmask == 255) {
- gl_convert = CopyShadowRGBToABGR;
- } else if (redmask == 255<<8) {
- gl_convert = CopyShadowRGBToBGRA;
- } else if (redmask == 255<<24) {
- gl_convert = CopyShadowRGBToRGBA;
- }
- } else {
- gl_pixelsize = 4;
- gl_upsidedown = SDL_TRUE;
- gl_copyshadow = CopyShadowDirect;
- if (redmask == 255<<16) {
- osmesa_format = OSMESA_ARGB;
- } else if (redmask == 255<<8) {
- osmesa_format = OSMESA_BGRA;
- } else if (redmask == 255<<24) {
- osmesa_format = OSMESA_RGBA;
- } else {
- /* ABGR format unsupported */
- osmesa_format = OSMESA_BGRA;
- gl_convert = ConvertBGRAToABGR;
- }
- }
- break;
- default:
- if (tinygl_present) {
- SDL_AtariGL_Quit(this, SDL_FALSE);
- return 0;
- }
- gl_pixelsize = 1;
- gl_copyshadow = CopyShadowDirect;
- osmesa_format = OSMESA_COLOR_INDEX;
- break;
-	}
-
-	/* Try to keep current context if possible */
-	recreatecontext=1;
-	if (gl_shadow &&
- (gl_curformat == osmesa_format) &&
- (gl_curwidth == current->w) &&
- (gl_curheight == current->h)) {
- recreatecontext = 0;
-	}
-	if (recreatecontext) {
- SDL_AtariGL_Quit(this, SDL_FALSE);
-
- gl_shadow = this->gl_data->OSMesaCreateLDG(
- osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
- );
-
- if (gl_shadow) {
- gl_curformat = osmesa_format;
- gl_curwidth = current->w;
- gl_curheight = current->h;
- } else {
- gl_curformat = 0;
- gl_curwidth = 0;
- gl_curheight = 0;
- }
-	}
-
-	return (gl_shadow != NULL);
-}
-
-/*--- Conversions routines from shadow buffer to the screen ---*/
+	gl_active = (gl_ctx != NULL);
+#endif
 
-static void CopyShadowNull(_THIS, SDL_Surface *surface)
-{
+	return (gl_active);
 }
 
-static void CopyShadowDirect(_THIS, SDL_Surface *surface)
+void SDL_AtariGL_Quit(_THIS)
 {
-	int y, srcpitch, dstpitch;
-	Uint8 *srcline, *dstline;
-
-	srcline = gl_shadow;
-	srcpitch = surface->w * gl_pixelsize;
-	dstline = (void *)((Uint8 *)surface->pixels + surface->offset);
-	dstpitch = surface->pitch;
-	if (gl_upsidedown) {
- srcline += (surface->h-1)*srcpitch;
- srcpitch = -srcpitch;
-	}
-
-	for (y=0; y<surface->h; y++) {
- SDL_memcpy(dstline, srcline, srcpitch);
-
- srcline += srcpitch;
- dstline += dstpitch;
+#if SDL_VIDEO_OPENGL
+	if (gl_ctx) {
+ OSMesaDestroyContext(gl_ctx);
+ gl_ctx = NULL;
 	}
+#endif /* SDL_VIDEO_OPENGL */
+	gl_active = 0;
 }
 
-static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface)
+int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
 {
-	int x,y, srcpitch, dstpitch;
-	Uint16 *dstline, *dstcol;
-	Uint8 *srcline, *srccol;
-
-	srcline = (Uint8 *)gl_shadow;
-	srcpitch = surface->w * gl_pixelsize;
-	dstline = (void *)((Uint8 *)surface->pixels + surface->offset);
-	dstpitch = surface->pitch >>1;
-	if (gl_upsidedown) {
- srcline += (surface->h-1)*srcpitch;
- srcpitch = -srcpitch;
-	}
-
-	for (y=0; y<surface->h; y++) {
- srccol = srcline;
- dstcol = dstline;
- for (x=0; x<surface->w; x++) {
- Uint16 dstcolor;
-			
- dstcolor = ((*srccol++)<<7) & (31<<10);
- dstcolor |= ((*srccol++)<<2) & (31<<5);
- dstcolor |= ((*srccol++)>>3) & 31;
- *dstcol++ = dstcolor;
- }
-
- srcline += srcpitch;
- dstline += dstpitch;

```

(Patch may be truncated, please check the link at the top of this post.)
