diff src/video/x11/SDL_x11window.c @ 1952:420716272158

Implemented X11 OpenGL support. Added support for the SDL_VIDEO_OPENGL environment variable.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 28 Jul 2006 08:43:17 +0000
parents 7177581dc9fa
children ba0d62354872
line wrap: on
line diff
--- a/src/video/x11/SDL_x11window.c	Thu Jul 27 06:53:23 2006 +0000
+++ b/src/video/x11/SDL_x11window.c	Fri Jul 28 08:43:17 2006 +0000
@@ -135,7 +135,7 @@
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_DisplayData *displaydata =
-        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
     Visual *visual;
     int depth;
     XSetWindowAttributes xattr;
@@ -153,9 +153,23 @@
     }
 */
 #endif
+#ifdef SDL_VIDEO_OPENGL_GLX
     if (window->flags & SDL_WINDOW_OPENGL) {
-        /* FIXME: get the glx visual */
-    } else {
+        XVisualInfo *vinfo;
+
+        if (X11_GL_Initialize(_this) < 0) {
+            return -1;
+        }
+        vinfo = X11_GL_GetVisual(_this, data->display, displaydata->screen);
+        if (!vinfo) {
+            return -1;
+        }
+        visual = vinfo->visual;
+        depth = vinfo->depth;
+        XFree(vinfo);
+    } else
+#endif
+    {
         visual = displaydata->visual;
         depth = displaydata->depth;
     }
@@ -203,6 +217,15 @@
                       window->w, window->h, 0, depth, InputOutput, visual,
                       (CWOverrideRedirect | CWBackPixel | CWBorderPixel |
                        CWColormap), &xattr);
+    if (!w) {
+#ifdef SDL_VIDEO_OPENGL_GLX
+        if (window->flags & SDL_WINDOW_OPENGL) {
+            X11_GL_Shutdown(_this);
+        }
+#endif
+        SDL_SetError("Couldn't create window");
+        return -1;
+    }
 
     sizehints = XAllocSizeHints();
     if (sizehints) {
@@ -370,27 +393,26 @@
 
     /* Finally, show the window */
     if (window->flags & SDL_WINDOW_SHOWN) {
+        XEvent event;
+
         XMapRaised(data->display, w);
+        do {
+            XCheckWindowEvent(data->display, w, StructureNotifyMask, &event);
+        } while (event.type != MapNotify);
     }
-    XSync(data->display, False);
 
     if (SetupWindowData(_this, window, w, SDL_TRUE) < 0) {
+#ifdef SDL_VIDEO_OPENGL_GLX
+        if (window->flags & SDL_WINDOW_OPENGL) {
+            X11_GL_Shutdown(_this);
+        }
+#endif
         XDestroyWindow(data->display, w);
         return -1;
     }
 
     X11_SetWindowTitle(_this, window);
 
-#ifdef SDL_VIDEO_OPENGL
-    /*
-       if (window->flags & SDL_WINDOW_OPENGL) {
-       if (X11_GL_SetupWindow(_this, window) < 0) {
-       X11_DestroyWindow(_this, window);
-       return -1;
-       }
-       }
-     */
-#endif
     return 0;
 }
 
@@ -486,7 +508,7 @@
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     SDL_DisplayData *displaydata =
-        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+        (SDL_DisplayData *) SDL_GetDisplayFromWindow(window)->driverdata;
     Display *display = data->videodata->display;
     int x, y;
 
@@ -576,12 +598,10 @@
 
     if (data) {
         Display *display = data->videodata->display;
-#ifdef SDL_VIDEO_OPENGL
-        /*
-           if (window->flags & SDL_WINDOW_OPENGL) {
-           X11_GL_CleanupWindow(_this, window);
-           }
-         */
+#ifdef SDL_VIDEO_OPENGL_GLX
+        if (window->flags & SDL_WINDOW_OPENGL) {
+            X11_GL_Shutdown(_this);
+        }
 #endif
 #ifdef X_HAVE_UTF8_STRING
         if (data->ic) {