Index: Makefile.dc
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/Makefile.dc,v
retrieving revision 1.1
diff -u -u -r1.1 Makefile.dc
--- Makefile.dc	5 Oct 2002 16:50:56 -0000	1.1
+++ Makefile.dc	5 Jul 2005 15:13:21 -0000
@@ -7,7 +7,7 @@
 DEFS =-DNO_SIGNAL_H -DENABLE_DC
 
 ifdef GL
-DEFS += -DHAVE_OPENGL
+DEFS += -DHAVE_OPENGL -DENABLE_OPENGLHQ
 TARGET = libSDL_gl.a
 else
 TARGET = libSDL.a
Index: configure.in
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/configure.in,v
retrieving revision 1.120.2.5
diff -u -u -r1.120.2.5 configure.in
--- configure.in	15 Dec 2004 10:19:05 -0000	1.120.2.5
+++ configure.in	5 Jul 2005 15:13:26 -0000
@@ -1081,7 +1081,9 @@
         ])
         AC_MSG_RESULT($video_opengl)
         if test x$video_opengl = xyes; then
-            CFLAGS="$CFLAGS -DHAVE_OPENGL"
+            CFLAGS="$CFLAGS -DHAVE_OPENGL -DENABLE_OPENGLHQ"
+	    VIDEO_SUBDIRS="$VIDEO_SUBDIRS openglhq"
+	    VIDEO_DRIVERS="$VIDEO_DRIVERS openglhq/libvideo_openglhq.la"
             if test x$use_dlopen != xyes; then
                 AC_CHECK_LIB(dl, dlopen, SYSTEM_LIBS="$SYSTEM_LIBS -ldl")
             fi
@@ -1125,7 +1127,9 @@
 CheckMacGL()
 {
     if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
-        CFLAGS="$CFLAGS -DHAVE_OPENGL"
+        CFLAGS="$CFLAGS -DHAVE_OPENGL -DENABLE_OPENGLHQ"
+        VIDEO_SUBDIRS="$VIDEO_SUBDIRS openglhq" 
+        VIDEO_DRIVERS="$VIDEO_DRIVERS openglhq/libvideo_openglhq.la" 
         case "$target" in
             *-*-darwin*)
                 SYSTEM_LIBS="$SYSTEM_LIBS -framework OpenGL -framework AGL"
@@ -1555,6 +1559,11 @@
     CFLAGS="$CFLAGS -DENABLE_WINDIB"
     VIDEO_SUBDIRS="$VIDEO_SUBDIRS windib"
     VIDEO_DRIVERS="$VIDEO_DRIVERS windib/libvideo_windib.la"
+    # Enable OpenglHQ 
+    CFLAGS="$CFLAGS -DENABLE_OPENGLHQ" 
+    SYSTEM_LIBS="$SYSTEM_LIBS -lopengl32" 
+    VIDEO_SUBDIRS="$VIDEO_SUBDIRS openglhq" 
+    VIDEO_DRIVERS="$VIDEO_DRIVERS openglhq/libvideo_openglhq.la" 
     # See if we should enable the DirectX driver
     if test x$use_directx = xyes; then
         CFLAGS="$CFLAGS -DENABLE_DIRECTX"
@@ -2882,6 +2891,7 @@
 src/video/macdsp/Makefile
 src/video/macrom/Makefile
 src/video/nanox/Makefile
+src/video/openglhq/Makefile
 src/video/photon/Makefile
 src/video/picogui/Makefile
 src/video/ps2gs/Makefile
Index: include/SDL_video.h
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/include/SDL_video.h,v
retrieving revision 1.16.2.4
diff -u -u -r1.16.2.4 SDL_video.h
--- include/SDL_video.h	19 Dec 2004 22:38:47 -0000	1.16.2.4
+++ include/SDL_video.h	5 Jul 2005 15:13:29 -0000
@@ -291,6 +291,14 @@
 extern DECLSPEC SDL_Rect ** SDLCALL SDL_ListModes(SDL_PixelFormat *format, Uint32 flags);
 
 /*
+ * If possible, retrieves the current resolution of the user's display. If this
+ * operation is supported and succeeds, the width and height are written to the
+ * values pointed to by the parameters and 1 is returned. If unsupported or
+ * unsuccessful, the pointed to values are not touched and 0 is returned.
+ */
+extern DECLSPEC int SDLCALL SDL_GetDesktopMode(int *width, int *height);
+
+/*
  * Set up a video mode with the specified width, height and bits-per-pixel.
  *
  * If 'bpp' is 0, it is treated as the current display bits per pixel.
Index: src/Makefile.am
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/Makefile.am,v
retrieving revision 1.4.2.1
diff -u -u -r1.4.2.1 Makefile.am
--- src/Makefile.am	23 Feb 2004 04:53:37 -0000	1.4.2.1
+++ src/Makefile.am	5 Jul 2005 15:13:29 -0000
@@ -26,6 +26,7 @@
 libSDL_la_LIBADD =		\
 	main/libarch.la		\
 	@SDL_EXTRALIBS@		\
+	@ALSA_LIBS@		\
 	@SYSTEM_LIBS@
 libSDL_la_DEPENDENCIES =	\
 	main/libarch.la		\
Index: src/events/SDL_events.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/events/SDL_events.c,v
retrieving revision 1.9.2.1
diff -u -u -r1.9.2.1 SDL_events.c
--- src/events/SDL_events.c	23 Feb 2004 04:53:43 -0000	1.9.2.1
+++ src/events/SDL_events.c	5 Jul 2005 15:13:29 -0000
@@ -180,7 +180,10 @@
 		SDL_EventThread = NULL;
 		SDL_DestroyMutex(SDL_EventLock.lock);
 	}
-	SDL_DestroyMutex(SDL_EventQ.lock);
+	if (SDL_EventQ.lock) {
+		SDL_DestroyMutex(SDL_EventQ.lock);
+		SDL_EventQ.lock = NULL;
+	}
 }
 
 Uint32 SDL_EventThreadID(void)
Index: src/video/Makefile.am
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/Makefile.am,v
retrieving revision 1.16
diff -u -u -r1.16 Makefile.am
--- src/video/Makefile.am	22 Aug 2003 05:51:19 -0000	1.16
+++ src/video/Makefile.am	5 Jul 2005 15:13:29 -0000
@@ -6,6 +6,7 @@
 # Define which subdirectories need to be built
 SUBDIRS = @VIDEO_SUBDIRS@
 DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \
+	       openglhq \
                wincommon windib windx5 \
                maccommon macdsp macrom riscos quartz \
                bwindow ps2gs photon cybergfx epoc picogui \
Index: src/video/SDL_glfuncs.h
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/SDL_glfuncs.h,v
retrieving revision 1.1.1.1.2.1
diff -u -u -r1.1.1.1.2.1 SDL_glfuncs.h
--- src/video/SDL_glfuncs.h	21 Sep 2003 18:10:21 -0000	1.1.1.1.2.1
+++ src/video/SDL_glfuncs.h	5 Jul 2005 15:13:30 -0000
@@ -4,6 +4,7 @@
 */
 #define SDL_PROC_UNUSED(ret,func,params)
 SDL_PROC_UNUSED(void,glAccum,(GLenum,GLfloat))
+SDL_PROC(void,glActiveTexture,(GLenum))
 SDL_PROC_UNUSED(void,glAlphaFunc,(GLenum,GLclampf))
 SDL_PROC_UNUSED(GLboolean,glAreTexturesResident,(GLsizei,const GLuint*,GLboolean*))
 SDL_PROC_UNUSED(void,glArrayElement,(GLint))
@@ -11,7 +12,7 @@
 SDL_PROC(void,glBindTexture,(GLenum,GLuint))
 SDL_PROC_UNUSED(void,glBitmap,(GLsizei,GLsizei,GLfloat,GLfloat,GLfloat,GLfloat,const GLubyte*))
 SDL_PROC(void,glBlendFunc,(GLenum,GLenum))
-SDL_PROC_UNUSED(void,glCallList,(GLuint))
+SDL_PROC(void,glCallList,(GLuint))
 SDL_PROC_UNUSED(void,glCallLists,(GLsizei,GLenum,const GLvoid*))
 SDL_PROC_UNUSED(void,glClear,(GLbitfield))
 SDL_PROC_UNUSED(void,glClearAccum,(GLfloat,GLfloat,GLfloat,GLfloat))
@@ -61,7 +62,7 @@
 SDL_PROC_UNUSED(void,glCopyTexSubImage1D,(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width))
 SDL_PROC(void,glCopyTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height))
 SDL_PROC_UNUSED(void,glCullFace,(GLenum mode))
-SDL_PROC_UNUSED(void,glDeleteLists,(GLuint list, GLsizei range))
+SDL_PROC(void,glDeleteLists,(GLuint list, GLsizei range))
 SDL_PROC(void,glDeleteTextures,(GLsizei n, const GLuint *textures))
 SDL_PROC_UNUSED(void,glDepthFunc,(GLenum func))
 SDL_PROC_UNUSED(void,glDepthMask,(GLboolean flag))
@@ -76,9 +77,9 @@
 SDL_PROC_UNUSED(void,glEdgeFlagPointer,(GLsizei stride, const GLvoid *pointer))
 SDL_PROC_UNUSED(void,glEdgeFlagv,(const GLboolean *flag))
 SDL_PROC(void,glEnable,(GLenum cap))
-SDL_PROC_UNUSED(void,glEnableClientState,(GLenum array))
+SDL_PROC(void,glEnableClientState,(GLenum array))
 SDL_PROC(void,glEnd,(void))
-SDL_PROC_UNUSED(void,glEndList,(void))
+SDL_PROC(void,glEndList,(void))
 SDL_PROC_UNUSED(void,glEvalCoord1d,(GLdouble u))
 SDL_PROC_UNUSED(void,glEvalCoord1dv,(const GLdouble *u))
 SDL_PROC_UNUSED(void,glEvalCoord1f,(GLfloat u))
@@ -92,7 +93,7 @@
 SDL_PROC_UNUSED(void,glEvalPoint1,(GLint i))
 SDL_PROC_UNUSED(void,glEvalPoint2,(GLint i, GLint j))
 SDL_PROC_UNUSED(void,glFeedbackBuffer,(GLsizei size, GLenum type, GLfloat *buffer))
-SDL_PROC_UNUSED(void,glFinish,(void))
+SDL_PROC(void,glFinish,(void))
 SDL_PROC(void,glFlush,(void))
 SDL_PROC_UNUSED(void,glFogf,(GLenum pname, GLfloat param))
 SDL_PROC_UNUSED(void,glFogfv,(GLenum pname, const GLfloat *params))
@@ -100,7 +101,7 @@
 SDL_PROC_UNUSED(void,glFogiv,(GLenum pname, const GLint *params))
 SDL_PROC_UNUSED(void,glFrontFace,(GLenum mode))
 SDL_PROC_UNUSED(void,glFrustum,(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar))
-SDL_PROC_UNUSED(GLuint,glGenLists,(GLsizei range))
+SDL_PROC(GLuint,glGenLists,(GLsizei range))
 SDL_PROC(void,glGenTextures,(GLsizei n, GLuint *textures))
 SDL_PROC_UNUSED(void,glGetBooleanv,(GLenum pname, GLboolean *params))
 SDL_PROC_UNUSED(void,glGetClipPlane,(GLenum plane, GLdouble *equation))
@@ -180,7 +181,7 @@
 SDL_PROC(void,glMatrixMode,(GLenum mode))
 SDL_PROC_UNUSED(void,glMultMatrixd,(const GLdouble *m))
 SDL_PROC_UNUSED(void,glMultMatrixf,(const GLfloat *m))
-SDL_PROC_UNUSED(void,glNewList,(GLuint list, GLenum mode))
+SDL_PROC(void,glNewList,(GLuint list, GLenum mode))
 SDL_PROC_UNUSED(void,glNormal3b,(GLbyte nx, GLbyte ny, GLbyte nz))
 SDL_PROC_UNUSED(void,glNormal3bv,(const GLbyte *v))
 SDL_PROC_UNUSED(void,glNormal3d,(GLdouble nx, GLdouble ny, GLdouble nz))
@@ -240,7 +241,7 @@
 SDL_PROC_UNUSED(void,glRasterPos4s,(GLshort x, GLshort y, GLshort z, GLshort w))
 SDL_PROC_UNUSED(void,glRasterPos4sv,(const GLshort *v))
 SDL_PROC_UNUSED(void,glReadBuffer,(GLenum mode))
-SDL_PROC_UNUSED(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels))
+SDL_PROC(void,glReadPixels,(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels))
 SDL_PROC_UNUSED(void,glRectd,(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2))
 SDL_PROC_UNUSED(void,glRectdv,(const GLdouble *v1, const GLdouble *v2))
 SDL_PROC_UNUSED(void,glRectf,(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2))
@@ -252,11 +253,11 @@
 SDL_PROC_UNUSED(GLint,glRenderMode,(GLenum mode))
 SDL_PROC_UNUSED(void,glRotated,(GLdouble angle, GLdouble x, GLdouble y, GLdouble z))
 SDL_PROC_UNUSED(void,glRotatef,(GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
-SDL_PROC_UNUSED(void,glScaled,(GLdouble x, GLdouble y, GLdouble z))
+SDL_PROC(void,glScaled,(GLdouble x, GLdouble y, GLdouble z))
 SDL_PROC_UNUSED(void,glScalef,(GLfloat x, GLfloat y, GLfloat z))
 SDL_PROC_UNUSED(void,glScissor,(GLint x, GLint y, GLsizei width, GLsizei height))
 SDL_PROC_UNUSED(void,glSelectBuffer,(GLsizei size, GLuint *buffer))
-SDL_PROC_UNUSED(void,glShadeModel,(GLenum mode))
+SDL_PROC(void,glShadeModel,(GLenum mode))
 SDL_PROC_UNUSED(void,glStencilFunc,(GLenum func, GLint ref, GLuint mask))
 SDL_PROC_UNUSED(void,glStencilMask,(GLuint mask))
 SDL_PROC_UNUSED(void,glStencilOp,(GLenum fail, GLenum zfail, GLenum zpass))
@@ -295,7 +296,7 @@
 SDL_PROC_UNUSED(void,glTexCoordPointer,(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer))
 SDL_PROC(void,glTexEnvf,(GLenum target, GLenum pname, GLfloat param))
 SDL_PROC_UNUSED(void,glTexEnvfv,(GLenum target, GLenum pname, const GLfloat *params))
-SDL_PROC_UNUSED(void,glTexEnvi,(GLenum target, GLenum pname, GLint param))
+SDL_PROC(void,glTexEnvi,(GLenum target, GLenum pname, GLint param))
 SDL_PROC_UNUSED(void,glTexEnviv,(GLenum target, GLenum pname, const GLint *params))
 SDL_PROC_UNUSED(void,glTexGend,(GLenum coord, GLenum pname, GLdouble param))
 SDL_PROC_UNUSED(void,glTexGendv,(GLenum coord, GLenum pname, const GLdouble *params))
@@ -305,17 +306,18 @@
 SDL_PROC_UNUSED(void,glTexGeniv,(GLenum coord, GLenum pname, const GLint *params))
 SDL_PROC_UNUSED(void,glTexImage1D,(GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels))
 SDL_PROC(void,glTexImage2D,(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels))
+SDL_PROC(void,glTexImage3D,(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels))
 SDL_PROC_UNUSED(void,glTexParameterf,(GLenum target, GLenum pname, GLfloat param))
 SDL_PROC_UNUSED(void,glTexParameterfv,(GLenum target, GLenum pname, const GLfloat *params))
 SDL_PROC(void,glTexParameteri,(GLenum target, GLenum pname, GLint param))
 SDL_PROC_UNUSED(void,glTexParameteriv,(GLenum target, GLenum pname, const GLint *params))
 SDL_PROC_UNUSED(void,glTexSubImage1D,(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels))
 SDL_PROC(void,glTexSubImage2D,(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels))
-SDL_PROC_UNUSED(void,glTranslated,(GLdouble x, GLdouble y, GLdouble z))
+SDL_PROC(void,glTranslated,(GLdouble x, GLdouble y, GLdouble z))
 SDL_PROC_UNUSED(void,glTranslatef,(GLfloat x, GLfloat y, GLfloat z))
 SDL_PROC_UNUSED(void,glVertex2d,(GLdouble x, GLdouble y))
 SDL_PROC_UNUSED(void,glVertex2dv,(const GLdouble *v))
-SDL_PROC_UNUSED(void,glVertex2f,(GLfloat x, GLfloat y))
+SDL_PROC(void,glVertex2f,(GLfloat x, GLfloat y))
 SDL_PROC_UNUSED(void,glVertex2fv,(const GLfloat *v))
 SDL_PROC(void,glVertex2i,(GLint x, GLint y))
 SDL_PROC_UNUSED(void,glVertex2iv,(const GLint *v))
Index: src/video/SDL_sysvideo.h
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/SDL_sysvideo.h,v
retrieving revision 1.22.2.2
diff -u -u -r1.22.2.2 SDL_sysvideo.h
--- src/video/SDL_sysvideo.h	23 Feb 2004 04:53:48 -0000	1.22.2.2
+++ src/video/SDL_sysvideo.h	5 Jul 2005 15:13:31 -0000
@@ -80,6 +80,9 @@
 	 */
 	SDL_Rect **(*ListModes)(_THIS, SDL_PixelFormat *format, Uint32 flags);
 
+	/* Get the current resolution of the user's display. */
+	int (*GetDesktopMode)(_THIS, int *width, int *height);
+
 	/* Set the requested video mode, returning a surface which will be
 	   set to the SDL_VideoSurface.  The width and height will already
 	   be verified by ListModes(), and the video subsystem is free to
@@ -409,6 +412,9 @@
 #ifdef ENABLE_DUMMYVIDEO
 extern VideoBootStrap DUMMY_bootstrap;
 #endif
+#ifdef ENABLE_OPENGLHQ
+extern VideoBootStrap OPENGLHQ_bootstrap;
+#endif
 #ifdef ENABLE_XBIOS
 extern VideoBootStrap XBIOS_bootstrap;
 #endif
Index: src/video/SDL_video.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/SDL_video.c,v
retrieving revision 1.42.2.8
diff -u -u -r1.42.2.8 SDL_video.c
--- src/video/SDL_video.c	19 Dec 2004 22:38:47 -0000	1.42.2.8
+++ src/video/SDL_video.c	5 Jul 2005 15:13:33 -0000
@@ -123,6 +123,9 @@
 #ifdef ENABLE_DUMMYVIDEO
 	&DUMMY_bootstrap,
 #endif
+#ifdef ENABLE_OPENGLHQ
+	&OPENGLHQ_bootstrap,
+#endif
 	NULL
 };
 
@@ -337,6 +340,24 @@
 }
 
 /*
+ * If possible, retrieves the current resolution of the user's display. If this
+ * operation is supported and succeeds, the width and height are written to the
+ * values pointed to by the parameters and 1 is returned. If unsupported or
+ * unsuccessful, the pointed to values are not touched and 0 is returned.
+ */
+int SDL_GetDesktopMode(int *width, int *height)
+{
+	SDL_VideoDevice *video = current_video;
+	SDL_VideoDevice *this  = current_video;
+
+	if (video && video->GetDesktopMode) {
+		return video->GetDesktopMode(this, width, height);
+	} else {
+		return 0;
+	}
+}
+
+/*
  * Check to see if a particular video mode is supported.
  * It returns 0 if the requested mode is not supported under any bit depth,
  * or returns the bits-per-pixel of the closest available mode with the
@@ -745,6 +766,14 @@
 	/* Load GL symbols (before MakeCurrent, where we need glGetString). */
 	if ( flags & SDL_OPENGL ) {
 
+	/* If we're running OpenGL, make the context current */
+	if ( (video->screen->flags & SDL_OPENGL) &&
+	      video->GL_MakeCurrent ) {
+		if ( video->GL_MakeCurrent(this) < 0 ) {
+			return(NULL);
+		}
+	}
+
 #if (defined(macintosh) && !defined(__MWERKS__))
 #define __SDL_NOGETPROCADDR__
 #elif defined(__QNXNTO__) && (_NTO_VERSION < 630)
@@ -771,14 +800,6 @@
 	}
 #endif /* HAVE_OPENGL */
 
-	/* If we're running OpenGL, make the context current */
-	if ( (video->screen->flags & SDL_OPENGL) &&
-	      video->GL_MakeCurrent ) {
-		if ( video->GL_MakeCurrent(this) < 0 ) {
-			return(NULL);
-		}
-	}
-
 	/* Create a shadow surface if necessary */
 	/* There are three conditions under which we create a shadow surface:
 		1.  We need a particular bits-per-pixel that we didn't get.
@@ -1577,6 +1598,7 @@
 {
 	SDL_VideoDevice *video = current_video;
 	SDL_GL_UnlockRenderTarget(target);
+	video->glFinish();
 	video->GL_FreeRenderTarget(video, target);
 	free(target);
 }
Index: src/video/wincommon/SDL_syswm.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/wincommon/SDL_syswm.c,v
retrieving revision 1.7
diff -u -u -r1.7 SDL_syswm.c
--- src/video/wincommon/SDL_syswm.c	17 Aug 2002 18:03:06 -0000	1.7
+++ src/video/wincommon/SDL_syswm.c	5 Jul 2005 15:13:37 -0000
@@ -285,3 +285,15 @@
 		return(-1);
 	}
 }
+
+int WIN_GetDesktopMode(_THIS, int *width, int *height)
+{
+	DEVMODE dm;
+	if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm)) {
+		*width = dm.dmPelsWidth;
+		*height = dm.dmPelsHeight;
+		return 1;
+	} else {
+		return 0;
+	}
+}
Index: src/video/wincommon/SDL_syswm_c.h
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/wincommon/SDL_syswm_c.h,v
retrieving revision 1.4.2.1
diff -u -u -r1.4.2.1 SDL_syswm_c.h
--- src/video/wincommon/SDL_syswm_c.h	23 Feb 2004 04:53:53 -0000	1.4.2.1
+++ src/video/wincommon/SDL_syswm_c.h	5 Jul 2005 15:13:37 -0000
@@ -36,4 +36,4 @@
 extern int WIN_IconifyWindow(_THIS);
 extern SDL_GrabMode WIN_GrabInput(_THIS, SDL_GrabMode mode);
 extern int WIN_GetWMInfo(_THIS, SDL_SysWMinfo *info);
-
+extern int WIN_GetDesktopMode(_THIS, int *width, int *height);
Index: src/video/wincommon/SDL_wingl.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/wincommon/SDL_wingl.c,v
retrieving revision 1.12.2.5
diff -u -u -r1.12.2.5 SDL_wingl.c
--- src/video/wincommon/SDL_wingl.c	30 Nov 2004 18:52:52 -0000	1.12.2.5
+++ src/video/wincommon/SDL_wingl.c	5 Jul 2005 15:13:38 -0000
@@ -229,7 +229,6 @@
 }
 #endif /* !HAVE_OPENGL */
 
-#endif /* HAVE_OPENGL */
 
 int WIN_GL_SetupWindow(_THIS)
 {
@@ -597,6 +596,10 @@
 static void DestroyRenderTarget(_THIS, SDL_RenderTarget *target) 
 {
 	WIN_RenderTargetData *render_target = (WIN_RenderTargetData *)target->gl_data;
+	
+	if (render_target->hPbuffer && render_target->buffer) {
+		this->gl_data->wglReleaseTexImageARB(render_target->hPbuffer, render_target->buffer);
+	}
 	if (render_target->hPbufferRC) {
 		this->gl_data->wglDeleteContext(render_target->hPbufferRC);
 	}
Index: src/video/windib/SDL_dibvideo.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/windib/SDL_dibvideo.c,v
retrieving revision 1.20.2.2
diff -u -u -r1.20.2.2 SDL_dibvideo.c
--- src/video/windib/SDL_dibvideo.c	30 Nov 2004 18:52:53 -0000	1.20.2.2
+++ src/video/windib/SDL_dibvideo.c	5 Jul 2005 15:13:41 -0000
@@ -142,6 +142,7 @@
 	/* Set the function pointers */
 	device->VideoInit = DIB_VideoInit;
 	device->ListModes = DIB_ListModes;
+	device->GetDesktopMode = WIN_GetDesktopMode;
 	device->SetVideoMode = DIB_SetVideoMode;
 	device->UpdateMouse = WIN_UpdateMouse;
 	device->SetColors = DIB_SetColors;
Index: src/video/windx5/SDL_dx5video.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/windx5/SDL_dx5video.c,v
retrieving revision 1.21.2.2
diff -u -u -r1.21.2.2 SDL_dx5video.c
--- src/video/windx5/SDL_dx5video.c	30 Nov 2004 18:52:53 -0000	1.21.2.2
+++ src/video/windx5/SDL_dx5video.c	5 Jul 2005 15:13:45 -0000
@@ -591,6 +591,7 @@
 	/* Set the function pointers */
 	device->VideoInit = DX5_VideoInit;
 	device->ListModes = DX5_ListModes;
+	device->GetDesktopMode = WIN_GetDesktopMode;
 	device->SetVideoMode = DX5_SetVideoMode;
 	device->UpdateMouse = WIN_UpdateMouse;
 	device->CreateYUVOverlay = DX5_CreateYUVOverlay;
Index: src/video/x11/SDL_x11gl.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/x11/SDL_x11gl.c,v
retrieving revision 1.17.2.5
diff -u -u -r1.17.2.5 SDL_x11gl.c
--- src/video/x11/SDL_x11gl.c	30 Nov 2004 18:52:53 -0000	1.17.2.5
+++ src/video/x11/SDL_x11gl.c	5 Jul 2005 15:13:46 -0000
@@ -295,6 +295,7 @@
 	const char *extensions;
 	const char *glx_extensions;
 	
+	if (!this->glGetString) this->glGetString = X11_GL_GetProcAddress(this,"glGetString");
 	/* What extensions are available? */
 	extensions = (const char *)this->glGetString(GL_EXTENSIONS);
 	if ( this->gl_data->glXQueryExtensionsString ) {
@@ -346,6 +347,12 @@
 		this->GL_UnlockRenderTarget = NULL ;
 		this->GL_FreeRenderTarget = NULL;
 	}
+
+	/* ATI's driver lies: it works nicely and is supported, but is not reported in supported extensions */
+	/*if ( !ExtensionSupported("GLX_ATI_render_texture", glx_extensions) ) {
+		this->gl_data->glXBindTexImageATI = NULL;
+	}*/
+
 }
 
 /* Make the current context active */
@@ -444,6 +451,8 @@
 typedef struct X11_RenderTargetData {
 	GLXFBConfigSGIX config;
 	GLXPbuffer pbuffer;
+	int buffer;
+	GLXContext context;
 } X11_RenderTargetData;
 
 /* This is only used by X11_GL_CreateRenderTarget() */
@@ -526,10 +535,14 @@
 		GLX_PRESERVED_CONTENTS_SGIX, True,
 		GLX_PBUFFER_WIDTH, target->w,
 		GLX_PBUFFER_HEIGHT, target->h,
+		GLX_TEXTURE_FORMAT_ATI, GLX_TEXTURE_RGBA_ATI,
+		GLX_TEXTURE_TARGET_ATI, GLX_TEXTURE_2D_ATI,
 		None
 	};
 	int nConfigs;
 	GLXFBConfigSGIX *fbConfigs;
+	XVisualInfo *visinfo, visinfo_template;
+	int visuals;
 
 	/* Allocate memory for data */
 	render_target = (X11_RenderTargetData *)malloc(sizeof(*render_target));
@@ -537,6 +550,7 @@
 		SDL_OutOfMemory();
 		return(-1);
 	}
+	render_target->buffer = 0;
 	render_target->pbuffer = None;
 	target->gl_data = render_target;
 
@@ -575,6 +589,11 @@
 	attribs[i++] = attrib[2*SDL_GL_ACCUM_ALPHA_SIZE+1];
 	attribs[i++] = GLX_STEREO;
 	attribs[i++] = attrib[2*SDL_GL_STEREO+1];
+	if (this->gl_data->glXBindTexImageATI != NULL) {
+		attribs[i++] = GLX_BIND_TO_TEXTURE_RGBA_ATI;
+		attribs[i++] = GL_TRUE;
+	}
+
 	attribs[i++] = None;
 
 	/* Loop through available configs trying to create a pbuffer */
@@ -585,6 +604,7 @@
 		PrintFBConfigInfo(this, fbConfigs[i]);
 	}
 #endif
+
 	for ( i = 0; i < nConfigs; ++i ) {
 		XErrorFlag = 0;
 		if ( this->gl_data->glx_version >= MAKE_GLX_VERSION(1, 3) ) {
@@ -609,6 +629,27 @@
 		SDL_SetError("Couldn't create pbuffer with desired attributes");
 		return(-1);
 	}
+
+	/* create a separate GLXContext for the pbuffer */
+	memset(&visinfo_template, 0, sizeof(visinfo_template));
+	this->gl_data->glXGetFBConfigAttribSGIX(GFX_Display, render_target->config, GLX_VISUAL_ID, (int *)&visinfo_template.visualid);
+	visinfo = XGetVisualInfo(GFX_Display, VisualIDMask, &visinfo_template, &visuals);
+	if (visinfo == NULL) {
+		/* this fbConfig exists, but can't be rendered on screen, so there is no
+		   X visual for it, thus no XVisualInfo. Faking one seems to work. */
+		visinfo_template.visual = DefaultVisual(GFX_Display, SDL_Screen);
+		visinfo_template.screen = SDL_Screen;
+		this->gl_data->glXGetFBConfigAttribSGIX(GFX_Display, render_target->config, GLX_BUFFER_SIZE, &visinfo_template.depth);
+		this->gl_data->glXGetFBConfigAttribSGIX(GFX_Display, render_target->config, GLX_X_VISUAL_TYPE_EXT, &visinfo_template.class);
+		this->gl_data->glXGetFBConfigAttribSGIX(GFX_Display, render_target->config, GLX_RED_SIZE, &visinfo_template.bits_per_rgb);
+		visinfo = &visinfo_template;
+	}
+	render_target->context = this->gl_data->glXCreateContext(GFX_Display, visinfo, glx_context, True);
+	if (render_target->context == NULL) {
+		SDL_SetError("Could not create GL context for pbuffer, visual ID 0x%x\n",visinfo->visualid);
+		return (-1);
+	}
+
 	return(0);
 }
 
@@ -670,25 +711,61 @@
 void X11_GL_LockRenderTarget(_THIS, SDL_RenderTarget *target)
 {
 	X11_RenderTargetData *render_target = (X11_RenderTargetData *)target->gl_data;
+
+	if (this->gl_data->glXBindTexImageATI != NULL) {
+		/* Release the pbuffer so it can be rendered to */
+		if ( target->texture && render_target->buffer ) {
+			this->gl_data->glXReleaseTexImageATI(GFX_Display, render_target->pbuffer, render_target->buffer);
+		}
+	}
 	/* Set the draw target */
-	this->gl_data->glXMakeCurrent(GFX_Display, render_target->pbuffer, glx_context);
+	this->gl_data->glXMakeCurrent(GFX_Display, render_target->pbuffer, render_target->context);
 	XSync( GFX_Display, False );
 }
 
 void X11_GL_UnlockRenderTarget(_THIS, SDL_RenderTarget *target)
 {
+	X11_RenderTargetData *render_target = (X11_RenderTargetData *)target->gl_data;
 	/* Update the texture with the pbuffer contents */
 	if ( target->texture ) {
-		this->glBindTexture(GL_TEXTURE_2D, target->texture);
-		this->glCopyTexSubImage2D(GL_TEXTURE_2D,
-					  0,
-					  0, 0,
-					  0, 0,
-					  target->w, target->h);
+		if (this->gl_data->glXBindTexImageATI != NULL) {
+			int drawBuffer = 0;
+			this->glGetIntegerv(GL_DRAW_BUFFER, &drawBuffer);
+			/* Reset the draw target */
+			this->gl_data->glXMakeCurrent(GFX_Display, SDL_Window, glx_context);
+			this->glBindTexture(GL_TEXTURE_2D, target->texture);
+			switch(drawBuffer) {
+			case GL_FRONT:
+			case GL_FRONT_LEFT:
+				render_target->buffer = GLX_FRONT_LEFT_ATI;
+				break;
+			case GL_FRONT_RIGHT:
+				render_target->buffer = GLX_FRONT_RIGHT_ATI;
+				break;
+			case GL_BACK:
+			case GL_BACK_LEFT:
+				render_target->buffer = GLX_BACK_LEFT_ATI;
+				break;
+			case GL_BACK_RIGHT:
+				render_target->buffer = GLX_BACK_RIGHT_ATI;
+				break;
+			default:
+				render_target->buffer = GLX_FRONT_LEFT_ATI;
+				break;
+			}
+			this->gl_data->glXBindTexImageATI(GFX_Display, render_target->pbuffer, render_target->buffer);
+		} else {
+			this->glBindTexture(GL_TEXTURE_2D, target->texture);
+			this->glCopyTexSubImage2D(GL_TEXTURE_2D,
+						  0,
+						  0, 0,
+						  0, 0,
+						  target->w, target->h);
+			/* Reset the draw target */
+			this->gl_data->glXMakeCurrent(GFX_Display, SDL_Window, glx_context);
+		}
 	}
 
-	/* Reset the draw target */
-	this->gl_data->glXMakeCurrent(GFX_Display, SDL_Window, glx_context);
 	XSync( GFX_Display, False );
 }
 
@@ -696,6 +773,10 @@
 {
 	X11_RenderTargetData *render_target = (X11_RenderTargetData *)target->gl_data;
 	if ( render_target->pbuffer != None ) {
+		if (this->gl_data->glXBindTexImageATI != NULL && render_target->buffer ) {
+			this->gl_data->glXReleaseTexImageATI(GFX_Display, render_target->pbuffer, render_target->buffer);
+		}
+		this->gl_data->glXDestroyContext(GFX_Display, render_target->context);
 		this->gl_data->glXDestroyGLXPbufferSGIX(GFX_Display, render_target->pbuffer);
 	}
 	free(render_target);
@@ -837,6 +918,13 @@
 			(void (*)(Display*, GLXPbuffer)) dlsym( handle, "glXDestroyGLXPbufferSGIX" );
 	}
 
+	/* It's important to use glXGetProcAddress: these are not available via dlsym in ATI's linux driver */
+	this->gl_data->glXBindTexImageATI =
+		(void (*)(Display*, GLXPbuffer, int)) X11_GL_GetProcAddress(this,"glXBindTexImageATI"); 
+	this->gl_data->glXReleaseTexImageATI =
+		(void (*)(Display*, GLXPbuffer, int)) X11_GL_GetProcAddress(this,"glXReleaseTexImageATI");
+	
+
 	if ( (this->gl_data->glXChooseVisual == NULL) || 
 	     (this->gl_data->glXCreateContext == NULL) ||
 	     (this->gl_data->glXDestroyContext == NULL) ||
Index: src/video/x11/SDL_x11gl_c.h
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/x11/SDL_x11gl_c.h,v
retrieving revision 1.7.2.3
diff -u -u -r1.7.2.3 SDL_x11gl_c.h
--- src/video/x11/SDL_x11gl_c.h	23 Feb 2004 04:53:54 -0000	1.7.2.3
+++ src/video/x11/SDL_x11gl_c.h	5 Jul 2005 15:13:46 -0000
@@ -128,6 +128,21 @@
 	      GLXFBConfigSGIX config,
 	      int *attrib_list );
 
+    /*
+     * Support for GLX_ATI_render_rexture extension
+     */
+
+    void (*glXBindTexImageATI)
+	    ( Display* dpy,
+	      GLXPbuffer pbuf,
+	      int buffer );
+ 
+    void (*glXReleaseTexImageATI)
+	    ( Display* dpy,
+	      GLXPbuffer pbuf,
+	      int buffer );
+ 
+
 #endif /* HAVE_OPENGL */
 };
 
@@ -181,4 +196,20 @@
 #define GLX_LARGEST_PBUFFER_SGIX           0x801C
 #endif
 
+#ifndef GLX_ATI_render_texture
+#define GLX_ATI_render_texture  1
+
+#define GLX_BIND_TO_TEXTURE_RGB_ATI         0x9800 // need real tokens here
+#define GLX_BIND_TO_TEXTURE_RGBA_ATI        0x9801
+#define GLX_TEXTURE_FORMAT_ATI              0x9802
+#define GLX_TEXTURE_TARGET_ATI              0x9803
+#define GLX_TEXTURE_RGB_ATI                 0x9805
+#define GLX_TEXTURE_RGBA_ATI                0x9806
+#define GLX_TEXTURE_2D_ATI                  0x980A
+#define GLX_FRONT_LEFT_ATI                  0x9813
+#define GLX_FRONT_RIGHT_ATI                 0x9814
+#define GLX_BACK_LEFT_ATI                   0x9815
+#define GLX_BACK_RIGHT_ATI                  0x9816
+#endif // GLX_ATI_render_texture
+
 #endif /* HAVE_OPENGL */
Index: src/video/x11/SDL_x11modes.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/x11/SDL_x11modes.c,v
retrieving revision 1.19.2.2
diff -u -u -r1.19.2.2 SDL_x11modes.c
--- src/video/x11/SDL_x11modes.c	30 Nov 2004 18:52:53 -0000	1.19.2.2
+++ src/video/x11/SDL_x11modes.c	5 Jul 2005 15:13:47 -0000
@@ -634,6 +634,13 @@
     }
 }
 
+int X11_GetDesktopMode(_THIS, int *width, int *height)
+{
+	*width = DisplayWidth(SDL_Display, SDL_Screen);
+	*height = DisplayHeight(SDL_Display, SDL_Screen);
+	return 1;
+}
+
 int X11_ResizeFullScreen(_THIS)
 {
     int x, y;
Index: src/video/x11/SDL_x11modes_c.h
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/x11/SDL_x11modes_c.h,v
retrieving revision 1.4.2.1
diff -u -u -r1.4.2.1 SDL_x11modes_c.h
--- src/video/x11/SDL_x11modes_c.h	23 Feb 2004 04:53:55 -0000	1.4.2.1
+++ src/video/x11/SDL_x11modes_c.h	5 Jul 2005 15:13:47 -0000
@@ -39,6 +39,7 @@
 extern int X11_GetVideoModes(_THIS);
 extern SDL_Rect **X11_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
 extern void X11_FreeVideoModes(_THIS);
+extern int X11_GetDesktopMode(_THIS, int *width, int *height);
 extern int X11_ResizeFullScreen(_THIS);
 extern void X11_WaitMapped(_THIS, Window win);
 extern void X11_WaitUnmapped(_THIS, Window win);
Index: src/video/x11/SDL_x11video.c
===================================================================
RCS file: /home/sdlweb/libsdl.org/cvs/SDL12/src/video/x11/SDL_x11video.c,v
retrieving revision 1.14.2.3
diff -u -u -r1.14.2.3 SDL_x11video.c
--- src/video/x11/SDL_x11video.c	19 Dec 2004 22:38:47 -0000	1.14.2.3
+++ src/video/x11/SDL_x11video.c	5 Jul 2005 15:13:48 -0000
@@ -139,6 +139,7 @@
 	/* Set the function pointers */
 	device->VideoInit = X11_VideoInit;
 	device->ListModes = X11_ListModes;
+	device->GetDesktopMode = X11_GetDesktopMode;
 	device->SetVideoMode = X11_SetVideoMode;
 	device->ToggleFullScreen = X11_ToggleFullScreen;
 	device->UpdateMouse = X11_UpdateMouse;
