Index: trunk/src/VBox/HostServices/SharedOpenGL/Makefile.kmk
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/Makefile.kmk	(revision 3707)
+++ trunk/src/VBox/HostServices/SharedOpenGL/Makefile.kmk	(revision 3708)
@@ -33,4 +33,5 @@
 	$(PATH_TOOL_$(VBOX_VCC_TOOL)_ATLMFC_INC) \
 	$(VBOX_PATH_SDK)
+VBoxSharedOpenGL_CXXFLAGS.linux = -pthread
 
 VBoxSharedOpenGL_SOURCES = \
@@ -55,4 +56,8 @@
 VBoxSharedOpenGL_LIBS.win = \
         $(PATH_SDK_WINPSDK_LIB)/opengl32.lib
+VBoxSharedOpenGL_LIBPATH.linux = \
+	$(VBOX_LIBPATH_X11)
+VBoxSharedOpenGL_LIBS.linux = \
+	GL
 
 include $(PATH_KBUILD)/subfooter.kmk
Index: trunk/src/VBox/HostServices/SharedOpenGL/gldrv.h
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/gldrv.h	(revision 3707)
+++ trunk/src/VBox/HostServices/SharedOpenGL/gldrv.h	(revision 3708)
@@ -23,14 +23,27 @@
 
 #include <iprt/types.h>
+#include <iprt/mem.h>
 
 #ifdef RT_OS_WINDOWS
 #define VBOX_OGL_DEBUG_WINDOW_OUTPUT
-#endif
-
+#elif defined(RT_OS_LINUX)
+#include <X11/Xlib.h>
+#include <GL/glx.h>
+#include <GL/glxext.h>
+ 
+typedef GLXContextID (*glXGetContextIDEXTProc) (const GLXContext);
+typedef GLXContext (*glXImportContextEXTProc) (Display *, GLXContextID);
+ 
+#define VBOX_OGL_DEBUG_WINDOW_OUTPUT
+#endif
+  
 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
+#if defined(RT_OS_WINDOWS)
 #define VBOX_OGL_GUEST_TO_HOST_HDC(a)       pClient->hdc
-#else
-#define VBOX_OGL_GUEST_TO_HOST_HDC(a)       a
-#endif
+#elif defined(RT_OS_LINUX)
+#define VBOX_OGL_GUEST_TO_HOST_HDC(a)       pClient->glxContext
+#endif
+#endif
+
 
 typedef struct
@@ -44,7 +57,37 @@
     uint32_t    cbLastParam;
 
+    struct
+    {
+#ifdef RT_OS_WINDOWS
+        HWND        hwnd;
+        HDC         hdc;
+        HGLRC       hglrc;
+#elif defined RT_OS_LINUX
+        Display     *dpy;
+        Window      win;
+        GLXContext  ctx;
+        GLXFBConfig *fbConfig;
+        XVisualInfo *visinfo;
+#endif
+    } enable;
+
 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
+#ifdef RT_OS_WINDOWS
     HWND        hwnd;
     HDC         hdc;
+#elif defined RT_OS_LINUX
+    Display     *dpy;
+    Window      xWindow;
+    GLXFBConfig actFBConfig;
+    int         winWidth, winHeight;
+    GLXFBConfig *PixelFormatToFBConfigMapper;
+    int         numFBConfigs;
+    GLXContext  glxContext;
+    PFNGLXCHOOSEFBCONFIGSGIXPROC glxChooseFBConfig;
+    PFNGLXGETVISUALFROMFBCONFIGSGIXPROC glxGetVisualFromFBConfig;
+    PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC glxCreateNewContext;
+    //glXGetContextIDEXTProc getContextIDPtr;
+    //glXImportContextEXTProc importContextEXTPtr;
+#endif
 #endif
 } VBOXOGLCTX, *PVBOXOGLCTX;
@@ -72,4 +115,16 @@
 #define DECLARE_HANDLE(a)  typedef HANDLE a
 #define WINAPI
+
+#define PFD_DOUBLEBUFFER   0x00000001
+#define PFD_STEREO         0x00000002
+#define PFD_DRAW_TO_WINDOW 0x00000004
+#define PFD_SUPPORT_OPENGL 0x00000020
+
+#define PFD_TYPE_RGBA       0
+#define PFD_TYPE_COLORINDEX 1
+
+#define PFD_MAIN_PLANE 0
+#define PFD_OVERLAY_PLANE 1
+#define PFD_UNDERLAY_PLANE (-1)
 
 typedef struct
@@ -149,4 +204,6 @@
 void vboxglDrvSwapBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer);
 
+int vboxglEnableOpenGL(VBOXOGLCTX *pClient);
+int vboxglDisableOpenGL(VBOXOGLCTX *pClient);
 
 RTUINTPTR vboxDrvIsExtensionAvailable(char *pszExtFunctionName);
Index: trunk/src/VBox/HostServices/SharedOpenGL/gllindrv.cpp
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/gllindrv.cpp	(revision 3707)
+++ trunk/src/VBox/HostServices/SharedOpenGL/gllindrv.cpp	(revision 3708)
@@ -4,4 +4,6 @@
  *
  * Simple buffered OpenGL functions
+ *
+ * Contributor: Alexander Eichner
  */
 
@@ -26,4 +28,124 @@
 #define LOG_GROUP LOG_GROUP_SHARED_OPENGL
 #include <VBox/log.h>
+#include <string.h>
+#include <stdio.h>
+
+/*static int (*X_handler)(Display *, XErrorEvent *) = NULL;
+static int x_errhandler(Display *d, XErrorEvent *e)
+{
+    return (X_handler(d, e));
+}
+
+static int (*XIO_handler)(Display *) = NULL;
+static int xio_errhandler(Display *d)
+{
+    return (XIO_handler(d));
+}*/
+
+static Bool WaitForNotify( Display *dpy, XEvent *event, XPointer arg ) {
+    return (event->type == MapNotify) && (event->xmap.window == (Window) arg);
+}
+
+/* from http://www.mesa3d.org/brianp/sig97/exten.htm */
+GLboolean vboxglCheckExtension(Display *dpy, int screenNum, char *extName )
+{
+   /*
+    ** Search for extName in the extensions string.  Use of strstr()
+    ** is not sufficient because extension names can be prefixes of
+    ** other extension names.  Could use strtok() but the constant
+    ** string returned by glGetString can be in read-only memory.
+    */
+    char *p = (char *) glXQueryExtensionsString(dpy, screenNum);
+    char *end;
+    int extNameLen;
+
+    extNameLen = strlen(extName);
+    end = p + strlen(p);
+
+    while (p < end) {
+        int n = strcspn(p, " ");
+        if ((extNameLen == n) && (strncmp(extName, p, n) == 0)) {
+            return GL_TRUE;
+        }
+        p += (n + 1);
+    }
+    return GL_FALSE;
+}
+
+
+/**
+ * Print parameters for a GLXFBConfig to stdout.
+ * Input:  dpy - the X display
+ *         screen - the X screen number
+ *         fbConfig - the fbconfig handle
+ *         horizFormat - if true, print in horizontal format
+ */
+void
+PrintFBConfigInfo(Display *dpy, int screen, GLXFBConfig config)
+{
+   int bufferSize, level, doubleBuffer, stereo, auxBuffers;
+   int redSize, greenSize, blueSize, alphaSize;
+   int depthSize, stencilSize;
+   int accumRedSize, accumBlueSize, accumGreenSize, accumAlphaSize;
+   int sampleBuffers, samples;
+   int drawableType, renderType, xRenderable, xVisual, id;
+
+   /* do queries using the GLX 1.3 tokens (same as the SGIX tokens) */
+   glXGetFBConfigAttrib(dpy, config, GLX_BUFFER_SIZE, &bufferSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_LEVEL, &level);
+   glXGetFBConfigAttrib(dpy, config, GLX_DOUBLEBUFFER, &doubleBuffer);
+   glXGetFBConfigAttrib(dpy, config, GLX_STEREO, &stereo);
+   glXGetFBConfigAttrib(dpy, config, GLX_AUX_BUFFERS, &auxBuffers);
+   glXGetFBConfigAttrib(dpy, config, GLX_RED_SIZE, &redSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_GREEN_SIZE, &greenSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_BLUE_SIZE, &blueSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_ALPHA_SIZE, &alphaSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_DEPTH_SIZE, &depthSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_STENCIL_SIZE, &stencilSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_RED_SIZE, &accumRedSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_GREEN_SIZE, &accumGreenSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_BLUE_SIZE, &accumBlueSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_ACCUM_ALPHA_SIZE, &accumAlphaSize);
+   glXGetFBConfigAttrib(dpy, config, GLX_SAMPLE_BUFFERS, &sampleBuffers);
+   glXGetFBConfigAttrib(dpy, config, GLX_SAMPLES, &samples);
+   glXGetFBConfigAttrib(dpy, config, GLX_DRAWABLE_TYPE, &drawableType);
+   glXGetFBConfigAttrib(dpy, config, GLX_RENDER_TYPE, &renderType);
+   glXGetFBConfigAttrib(dpy, config, GLX_X_RENDERABLE, &xRenderable);
+   glXGetFBConfigAttrib(dpy, config, GLX_X_VISUAL_TYPE, &xVisual);
+   if (!xRenderable || !(drawableType & GLX_WINDOW_BIT_SGIX))
+      xVisual = -1;
+
+   glXGetFBConfigAttrib(dpy, config, GLX_FBCONFIG_ID, &id);
+
+      printf("Id 0x%x\n", id);
+      printf("  Buffer Size: %d\n", bufferSize);
+      printf("  Level: %d\n", level);
+      printf("  Double Buffer: %s\n", doubleBuffer ? "yes" : "no");
+      printf("  Stereo: %s\n", stereo ? "yes" : "no");
+      printf("  Aux Buffers: %d\n", auxBuffers);
+      printf("  Red Size: %d\n", redSize);
+      printf("  Green Size: %d\n", greenSize);
+      printf("  Blue Size: %d\n", blueSize);
+      printf("  Alpha Size: %d\n", alphaSize);
+      printf("  Depth Size: %d\n", depthSize);
+      printf("  Stencil Size: %d\n", stencilSize);
+      printf("  Accum Red Size: %d\n", accumRedSize);
+      printf("  Accum Green Size: %d\n", accumGreenSize);
+      printf("  Accum Blue Size: %d\n", accumBlueSize);
+      printf("  Accum Alpha Size: %d\n", accumAlphaSize);
+      printf("  Sample Buffers: %d\n", sampleBuffers);
+      printf("  Samples/Pixel: %d\n", samples);
+      printf("  Drawable Types: ");
+      if (drawableType & GLX_WINDOW_BIT)  printf("Window ");
+      if (drawableType & GLX_PIXMAP_BIT)  printf("Pixmap ");
+      if (drawableType & GLX_PBUFFER_BIT)  printf("PBuffer");
+      printf("\n");
+      printf("  Render Types: ");
+      if (renderType & GLX_RGBA_BIT_SGIX)  printf("RGBA ");
+      if (renderType & GLX_COLOR_INDEX_BIT_SGIX)  printf("CI ");
+      printf("\n");
+      printf("  X Renderable: %s\n", xRenderable ? "yes" : "no");
+
+}
 
 /**
@@ -34,5 +156,83 @@
 int vboxglGlobalInit()
 {
-    vboxInitOpenGLExtensions();
+    Log(("vboxglGlobalInit\n"));
+
+    /*vboxInitOpenGLExtensions();*/
+    return VINF_SUCCESS;
+}
+
+
+/**
+ * Enable OpenGL
+ *
+ * @returns VBox error code
+ * @param   pClient         Client context
+ */
+int vboxglEnableOpenGL(PVBOXOGLCTX pClient)
+{
+    Display *dpy;
+    static int attribs[] = {
+        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+        GLX_RENDER_TYPE,   GLX_RGBA_BIT,
+        GLX_DOUBLEBUFFER,  True,  /* Request a double-buffered color buffer with */
+        GLX_RED_SIZE,      1,     /* the maximum number of bits per component    */
+        GLX_GREEN_SIZE,    1, 
+        GLX_BLUE_SIZE,     1,
+        None
+    };
+    int screen_num;
+    XSetWindowAttributes attr;
+    unsigned long mask;
+    int returnedFBConfigs;
+
+    if (!pClient->glxContext) 
+    {
+        /* we have to set up a rendering context to be able to use glGetString
+         * a window is created but is not mapped to screen (so it's not visible') 
+         * and a GLXContext is bound to it */
+        screen_num = DefaultScreen(pClient->dpy);
+        pClient->enable.fbConfig = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedFBConfigs);
+        Log(("vboxglGetString: returned FBConfigs: %d\n", returnedFBConfigs));
+        pClient->enable.visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, fbConfig[0]);
+        /* Create Window */
+        attr.background_pixel = 0;
+        attr.border_pixel = 0;
+        attr.colormap = XCreateColormap(pClient->dpy, RootWindow(dpy, screen_num), visinfo->visual, AllocNone);
+        attr.event_mask = StructureNotifyMask | ExposureMask;
+        mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+        pClient->enable.win = XCreateWindow(pClient->dpy, RootWindow(pClient->dpy, screen_num), 0, 0, 100, 100,
+		           0, visinfo->depth, InputOutput,
+		           visinfo->visual, mask, &attr);
+        /* Create Context */
+        pClient->enable.ctx = pClient->glxCreateNewContext(pClient->dpy, fbConfig[0], GLX_RGBA_TYPE, NULL, True);
+
+        glXMakeCurrent(pClient->dpy, pClient->enable.win, pClient->enable.ctx);
+    } 
+    else 
+    {
+        glXMakeCurrent(pClient->dpy, pClient->xWindow, pClient->glxContext);
+    }
+
+    return VINF_SUCCESS;
+}
+
+/**
+ * Disable OpenGL
+ *
+ * @returns VBox error code
+ * @param   pClient         Client context
+ */
+int vboxglDisableOpenGL(PVBOXOGLCTX pClient)
+{
+    /* Free all data */
+    glFlush();
+    if (!pClient->glxContext) 
+    {
+        glXMakeCurrent(pClient->dpy, 0, NULL);
+        XDestroyWindow(pClient->dpy, pClient->enable.win);
+        glXDestroyContext(pClient->dpy, pClient->enable.ctx);
+        XFree(pClient->enable.visinfo);
+        XFree(pClient->enable.fbConfig);
+    }
     return VINF_SUCCESS;
 }
@@ -46,5 +246,44 @@
 int vboxglConnect(PVBOXOGLCTX pClient)
 {
-    return VINF_SUCCESS;
+    int rc = VERR_NOT_IMPLEMENTED;
+    Log(("vboxglConnect\n"));
+    //pClient->getContextIDPtr = NULL;
+    //pClient->importContextEXTPtr = NULL;
+    pClient->PixelFormatToFBConfigMapper = NULL;
+    pClient->xWindow = 0;
+
+    pClient->dpy = XOpenDisplay(NULL);
+
+    if (pClient->dpy) {
+        int  screenNum, major, minor;
+
+        screenNum = DefaultScreen(pClient->dpy);
+        glXQueryVersion(pClient->dpy, &major, &minor);
+
+        if ((major == 1) && (minor >= 3)) {
+            Log(("Server GLX 1.3 supported\n"));
+            pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddress( 
+                                          (GLubyte *) "glXChooseFBConfig");
+            pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddress( 
+                                                 (GLubyte *) "glXGetVisualFromFBConfig");
+            pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddress(
+                                            (GLubyte *) "glXCreateNewContext");
+        } else if (vboxglCheckExtension(pClient->dpy, screenNum, "GLX_SGIX_fbconfig")) {
+            Log(("GLX_SGIX_fbconfig extension supported\n"));
+            pClient->glxChooseFBConfig = (PFNGLXCHOOSEFBCONFIGSGIXPROC) glXGetProcAddress( 
+                                          (GLubyte *) "glXChooseFBConfigSGIX");
+            pClient->glxGetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) glXGetProcAddress( 
+                                                 (GLubyte *) "glXGetVisualFromFBConfigSGIX");
+            pClient->glxCreateNewContext = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) glXGetProcAddress(
+                                            (GLubyte *) "glXCreateContextWithConfigSGIX");
+        } else {
+                Log(("Error no FBConfig supported\n"));
+                rc = VERR_NOT_IMPLEMENTED;
+        }
+        if (pClient->glxChooseFBConfig && pClient->glxGetVisualFromFBConfig && pClient->glxCreateNewContext)
+            rc = VINF_SUCCESS;
+    }
+
+    return rc;
 }
 
@@ -57,4 +296,21 @@
 int vboxglDisconnect(PVBOXOGLCTX pClient)
 {
+    Log(("vboxglDisconnect\n"));
+
+#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
+    if (pClient->dpy) {
+        if (pClient->xWindow != 0) {
+            XUnmapWindow(pClient->dpy, pClient->xWindow);
+            XDestroyWindow(pClient->dpy, pClient->xWindow);
+        }
+        if (pClient->PixelFormatToFBConfigMapper) {
+            XFree(pClient->PixelFormatToFBConfigMapper);
+        }
+        XCloseDisplay(pClient->dpy);
+    }
+    pClient->dpy = NULL;
+    pClient->xWindow = 0;
+    pClient->actFBConfig = NULL;
+#endif
     return VINF_SUCCESS;
 }
@@ -63,39 +319,129 @@
 void vboxglDrvCreateContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    OGL_CMD(DrvCreateContext, 4);
-    OGL_PARAM(HDC, hdc);
-    OGL_PARAM(uint32_t, cx);
-    OGL_PARAM(uint32_t, cy);
-    OGL_PARAM(BYTE, cColorBits);
-    OGL_PARAM(BYTE, iPixelType);
-    OGL_PARAM(BYTE, cDepthBits);
-
-    pClient->lastretval = 0; /** @todo */
+    XSetWindowAttributes attr;
+    XVisualInfo *visinfo = NULL;
+    unsigned long mask;
+    //GLXContext ctx;
+    GLXFBConfig fbConfig;
+    GLXContextID glrc;
+    int screen_num;
+    XEvent event;
+    OGL_CMD(DrvCreateContext, 1);
+    OGL_PARAM(HDC, hdc);
+
+    Log(("DrvCreateContext %x\n", hdc));
+#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
+
+    screen_num = DefaultScreen(pClient->dpy);
+    fbConfig = pClient->actFBConfig;
+
+#if 0
+    if (!fbConfig) {
+        /* Create a standard fbconfig */
+        int returnedNumFBConfigs;
+        GLXFBConfig *returnedFBConfigs;
+        static int attribs[] = {
+            GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
+            GLX_RENDER_TYPE,   GLX_RGBA_BIT,
+            GLX_DOUBLEBUFFER,  True,  /* Request a double-buffered color buffer with */
+            GLX_RED_SIZE,      1,     /* the maximum number of bits per component    */
+            GLX_GREEN_SIZE,    1, 
+            GLX_BLUE_SIZE,     1,
+            None
+        };
+
+        Log(("Warning: no GLXFBConfig set creating standard one\n"));
+        returnedFBConfigs = pClient->glxChooseFBConfig(pClient->dpy, screen_num, attribs, &returnedNumFBConfigs);
+        if (!returnedNumFBConfigs) {
+            pClient->lastretval = 0;
+            pClient->fHasLastError = true;
+            pClient->ulLastError   = glGetError();
+            return;
+        }
+        fbConfig = returnedFBConfigs[0];
+    }
+#endif
+
+    visinfo = pClient->glxGetVisualFromFBConfig(pClient->dpy, fbConfig);
+
+    if (pClient->xWindow == 0) {
+
+	/* window attributes */
+	attr.background_pixel = 0;
+	attr.border_pixel = 0;
+	attr.colormap = XCreateColormap(pClient->dpy, RootWindow(pClient->dpy, screen_num ), visinfo->visual, AllocNone);
+	attr.event_mask = StructureNotifyMask | ExposureMask;
+	mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+	pClient->xWindow = XCreateWindow(pClient->dpy, 
+	                                RootWindow(pClient->dpy, screen_num), 
+	                                0, 0, pClient->winWidth, pClient->winHeight, 0,
+	                                visinfo->depth, InputOutput,
+	                                visinfo->visual, mask, &attr);
+    }
+    XResizeWindow(pClient->dpy, pClient->xWindow, pClient->winWidth, pClient->winHeight);
+    pClient->glxContext = pClient->glxCreateNewContext(pClient->dpy, fbConfig, GLX_RGBA_TYPE, NULL, True);
+
+    XMapWindow(pClient->dpy, pClient->xWindow);
+    XIfEvent(pClient->dpy, &event, WaitForNotify, (XPointer)pClient->xWindow );
+    //glrc = pClient->getContextIDPtr(ctx);
+    glrc = 1;
+    Assert(glrc);
+#else
+    AssertFailed();
+    glrc = 0;
+#endif
+
+    pClient->lastretval = (uint64_t)glrc;
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
 void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
+    //GLXContext ctx;
     OGL_CMD(DrvDeleteContext, 1);
     OGL_PARAM(HGLRC, hglrc);
-    /** @todo */
-    pClient->lastretval = 0; /** @todo */
+    Log(("DrvDeleteContext %x\n", hglrc));
+    //ctx = pClient->importContextEXTPtr(pClient->dpy, hglrc);
+    glXDestroyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc));
+    pClient->lastretval = 1;
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
 void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
+    //GLXContext ctx;
     OGL_CMD(DrvSetContext, 2);
     OGL_PARAM(HDC, hdc);
     OGL_PARAM(HGLRC, hglrc);
-
-    pClient->lastretval = 0; /** @todo */
+    Log(("DrvSetContext %x %x\n", hdc, hglrc));
+#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
+    //ctx = pClient->importContextEXTPtr(pClient->dpy, hglrc);
+    pClient->lastretval = glXMakeCurrent(pClient->dpy, pClient->xWindow, 
+                                         VBOX_OGL_GUEST_TO_HOST_HDC(hglrc));
+    if (!pClient->lastretval)
+        Log(("glXMakeCurrent failed\n"));
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
+#else
+    AssertFailed();
+#endif
 }
 
 void vboxglDrvCopyContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
+    //GLXContext ctxSrc, ctxDst;
     OGL_CMD(DrvDeleteContext, 3);
     OGL_PARAM(HGLRC, hglrcSrc);
     OGL_PARAM(HGLRC, hglrcDst);
     OGL_PARAM(UINT,  mask);
-    pClient->lastretval = 0; /** @todo */
+    Log(("DrvCopyContext %x %x %x\n", hglrcSrc, hglrcDst, mask));
+    //ctxSrc = pClient->importContextEXTPtr(pClient->dpy, hglrcSrc);
+    //ctxDst = pClient->importContextEXTPtr(pClient->dpy, hglrcDst);
+    glXCopyContext(pClient->dpy, VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), VBOX_OGL_GUEST_TO_HOST_HDC(hglrc), mask);
+    pClient->lastretval = 1;
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
@@ -104,20 +450,28 @@
     OGL_CMD(DrvReleaseContext, 1);
     OGL_PARAM(HGLRC, hglrc);
+    Log(("DrvReleaseContext %x\n", hglrc));
+    /* clear current selection */
+    pClient->lastretval = glXMakeCurrent(pClient->dpy, 0, NULL);
+
+    if (!pClient->lastretval)
+        Log(("glXMakeCurrent failed\n"));
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
+}
+
+void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
+{
+    OGL_CMD(DrvCreateLayerContext, 2);
+    OGL_PARAM(HDC, hdc);
+    OGL_PARAM(int, iLayerPlane);
+
+    Log(("DrvCreateLayerContext %x\n", hdc));
+#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
     pClient->lastretval = 0; /** @todo */
-}
-
-void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
-{
-    OGL_CMD(DrvCreateLayerContext, 5);
-    OGL_PARAM(HDC, hdc);
-    OGL_PARAM(int, iLayerPlane);
-    OGL_PARAM(uint32_t, cx);
-    OGL_PARAM(uint32_t, cy);
-    OGL_PARAM(BYTE, cColorBits);
-    OGL_PARAM(BYTE, iPixelType);
-    OGL_PARAM(BYTE, cDepthBits);
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
+#else
     AssertFailed();
-    /** @todo create memory dc with the parameters above */
-    pClient->lastretval = 0; /** @todo */
+#endif
 }
 
@@ -128,4 +482,6 @@
     OGL_PARAM(HGLRC, hglrc2);
     pClient->lastretval = 0; /** @todo */
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
@@ -138,4 +494,6 @@
     OGL_PARAM(BOOL, bRealize);
     pClient->lastretval = 0; /** @todo */
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
@@ -146,13 +504,29 @@
     OGL_PARAM(UINT, fuPlanes);
     pClient->lastretval = 0; /** @todo */
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
 void vboxglDrvSetPixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
 {
-    OGL_CMD(DrvSetPixelFormat, 2);
+    int screen_num;
+    OGL_CMD(DrvSetPixelFormat, 4);
     OGL_PARAM(HDC, hdc);
     OGL_PARAM(int, iPixelFormat);
-
-    pClient->lastretval = 0; /** @todo */
+    OGL_PARAM(uint32_t, cx);
+    OGL_PARAM(uint32_t, cy);
+
+    Log(("vboxDrvSetPixelFormat %d\n", iPixelFormat));
+
+    /* Get GLXFBConfig based on the given ID */
+    pClient->actFBConfig = pClient->PixelFormatToFBConfigMapper[iPixelFormat-1];
+    screen_num = DefaultScreen(pClient->dpy);
+    PrintFBConfigInfo(pClient->dpy, screen_num, pClient->actFBConfig);
+    Log(("Window width: %d Window height: %d\n", cx, cy));
+    pClient->winWidth = cx;
+    pClient->winHeight = cy;
+    pClient->lastretval = true;
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
@@ -162,5 +536,8 @@
     OGL_PARAM(HDC, hdc);
 
-    pClient->lastretval = 0; /** @todo */
+    glXSwapBuffers(pClient->dpy, pClient->xWindow);
+    pClient->lastretval = 1;
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
@@ -178,4 +555,6 @@
 
     pClient->lastretval = 0; /** @todo */
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
@@ -189,4 +568,6 @@
     OGL_MEMPARAM(COLORREF, pcr);
     pClient->lastretval = 0; /** @todo */
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
@@ -204,4 +585,6 @@
     pcr = (COLORREF *)pClient->pLastParam;
     pClient->lastretval = 0; /** @todo */
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
@@ -209,4 +592,6 @@
 {
     LPPIXELFORMATDESCRIPTOR ppfd;
+    GLXFBConfig *allFBConfigs, matchingFBConfig;
+    int screenNum, glxReturnValue;
 
     OGL_CMD(DrvDescribePixelFormat, 3);
@@ -217,10 +602,80 @@
     ppfd = (LPPIXELFORMATDESCRIPTOR)pClient->pLastParam;
 
-    pClient->lastretval = 0; /** @todo */
+    Log(("iPixelFormat: %d\n", iPixelFormat));
+
+    if (!pClient->PixelFormatToFBConfigMapper) {
+        /* First get number of all visuals for the return value */
+        screenNum = DefaultScreen(pClient->dpy);
+        allFBConfigs = glXGetFBConfigs(pClient->dpy, screenNum, 
+                                            &pClient->numFBConfigs);
+        pClient->PixelFormatToFBConfigMapper = allFBConfigs;
+    }
+
+    if (nBytes == sizeof(PIXELFORMATDESCRIPTOR)) {
+        int redSize, greenSize, blueSize, alphaSize, xVisual, xRenderable;
+        /* Get GLXFBConfig which matches iPixelFormat */
+        matchingFBConfig = pClient->PixelFormatToFBConfigMapper[iPixelFormat-1];
+
+        Log(("Filling values into PIXELFORMATDESCRIPTOR\n"));
+        /* translate all values to theire corresponding Windows ones */
+        ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
+        ppfd->nVersion = 1;
+        ppfd->iLayerType = PFD_MAIN_PLANE;
+        ppfd->dwFlags =  0;
+
+        /* Set cColorBits */
+        glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_RED_SIZE, &redSize);
+        glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_GREEN_SIZE, &greenSize);
+        glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_BLUE_SIZE, &blueSize);
+        glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_ALPHA_SIZE, &alphaSize);
+        ppfd->cColorBits = redSize + greenSize + blueSize;
+        ppfd->cRedBits = redSize;
+        ppfd->cBlueBits = blueSize;
+        ppfd->cGreenBits = greenSize;
+        ppfd->cAlphaBits = alphaSize;
+
+        /* Set dwFlags */
+        if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DRAWABLE_TYPE, &glxReturnValue)) {
+            glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_VISUAL_ID, &xVisual);
+            glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_X_RENDERABLE, &xRenderable);
+            if ((glxReturnValue & GLX_WINDOW_BIT) && xVisual)
+                ppfd->dwFlags |= (PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL);
+        }
+        if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DOUBLEBUFFER, &glxReturnValue)) {
+            if (glxReturnValue)
+                ppfd->dwFlags |= PFD_DOUBLEBUFFER;
+        }
+        /* Set iPixelType */
+        if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_RENDER_TYPE, &glxReturnValue)) {
+            if (glxReturnValue & GLX_RGBA_BIT)
+                ppfd->iPixelType = PFD_TYPE_RGBA;
+            else if ((glxReturnValue & GLX_COLOR_INDEX_BIT) & !(glxReturnValue & GLX_RGBA_BIT))
+                ppfd->iPixelType = PFD_TYPE_COLORINDEX;
+        }
+        /* Set cDepthBits */
+        if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_DEPTH_SIZE, &glxReturnValue)) {
+            ppfd->cDepthBits = glxReturnValue;
+        } else {
+            ppfd->cDepthBits = 0;
+        }
+        /* Set cStencilBits */
+        if (!glXGetFBConfigAttrib(pClient->dpy, matchingFBConfig, GLX_STENCIL_SIZE, &glxReturnValue)) {
+            ppfd->cStencilBits = glxReturnValue;
+        } else {
+            ppfd->cStencilBits = 0;
+        }
+        /** @todo Fill in the rest */
+    }
+
+    pClient->lastretval = pClient->numFBConfigs;
+    pClient->fHasLastError = true;
+    pClient->ulLastError   = glGetError();
 }
 
 RTUINTPTR vboxDrvIsExtensionAvailable(char *pszExtFunctionName)
 {
-    return 0;
-}
-
+    RTUINTPTR pfnProc = (RTUINTPTR)glXGetProcAddress((const GLubyte *)pszExtFunctionName);
+    Log(("vboxDrvIsExtensionAvailable %s -> %d\n", pszExtFunctionName, !!pfnProc));
+    return pfnProc;
+}
+
Index: trunk/src/VBox/HostServices/SharedOpenGL/glwindrv.cpp
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/glwindrv.cpp	(revision 3707)
+++ trunk/src/VBox/HostServices/SharedOpenGL/glwindrv.cpp	(revision 3708)
@@ -105,4 +105,5 @@
     PIXELFORMATDESCRIPTOR pfd;
     int iFormat;
+    /** @todo should NOT use the desktop window -> crashes the Intel OpenGL driver */
     HDC hdc = GetDC(0);
 
@@ -131,4 +132,49 @@
 
 /**
+ * Enable OpenGL
+ *
+ * @returns VBox error code
+ * @param   pClient         Client context
+ */
+int vboxglEnableOpenGL(PVBOXOGLCTX pClient)
+{
+    PIXELFORMATDESCRIPTOR pfd;
+    int iFormat;
+
+    /** @todo should NOT use the desktop window -> crashes the Intel OpenGL driver */
+    pClient->enable.hdc = GetDC(0);
+
+    ZeroMemory(&pfd, sizeof(pfd));
+    pfd.nSize       = sizeof(pfd);
+    pfd.nVersion    = 1;
+    pfd.dwFlags     = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
+    pfd.iPixelType  = PFD_TYPE_RGBA;
+    pfd.cColorBits  = 24;
+    pfd.cDepthBits  = 16;
+    pfd.iLayerType  = PFD_MAIN_PLANE;
+    iFormat         = ChoosePixelFormat(pClient->enable.hdc, &pfd);
+    SetPixelFormat(pClient->enable.hdc, iFormat, &pfd);
+
+    pClient->enable.hglrc = wglCreateContext(pClient->enable.hdc);
+    wglMakeCurrent(pClient->enable.hdc, pClient->enable.hglrc);
+    return VINF_SUCCESS;
+}
+
+
+/**
+ * Disable OpenGL
+ *
+ * @returns VBox error code
+ * @param   pClient         Client context
+ */
+int vboxglDisableOpenGL(PVBOXOGLCTX pClient)
+{
+    wglMakeCurrent(NULL, NULL);
+    wglDeleteContext(pClient->enable.hglrc);
+    ReleaseDC(0, pClient->enable.hdc);
+    return VINF_SUCCESS;
+}
+
+/**
  * Client connect init
  *
Index: trunk/src/VBox/HostServices/SharedOpenGL/service.cpp
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/service.cpp	(revision 3707)
+++ trunk/src/VBox/HostServices/SharedOpenGL/service.cpp	(revision 3708)
@@ -287,4 +287,5 @@
                 else
                 {
+#ifdef __WIN__
                     /* Execute the function. */
                     if (vboxwglGetProcAddress(pszExtFnName))
@@ -292,5 +293,7 @@
                     else
                         rc = VERR_FILE_NOT_FOUND;
-
+#else
+                        rc = VERR_FILE_NOT_FOUND;
+#endif
                     if (VBOX_SUCCESS(rc))
                     {
Index: trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.cpp
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.cpp	(revision 3707)
+++ trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.cpp	(revision 3708)
@@ -31,6 +31,4 @@
 #include <VBox/log.h>
 
-
-
 /**
  * glGetString implementation
@@ -48,23 +46,5 @@
     int      rc = VINF_SUCCESS;
 
-#ifdef RT_OS_WINDOWS
-    PIXELFORMATDESCRIPTOR pfd;
-    int iFormat;
-    HDC hdc = GetDC(0);
-
-    ZeroMemory(&pfd, sizeof(pfd));
-    pfd.nSize       = sizeof(pfd);
-    pfd.nVersion    = 1;
-    pfd.dwFlags     = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
-    pfd.iPixelType  = PFD_TYPE_RGBA;
-    pfd.cColorBits  = 24;
-    pfd.cDepthBits  = 16;
-    pfd.iLayerType  = PFD_MAIN_PLANE;
-    iFormat         = ChoosePixelFormat(hdc, &pfd);
-    SetPixelFormat(hdc, iFormat, &pfd);
-
-    HGLRC hRC = wglCreateContext(hdc);
-    wglMakeCurrent(hdc, hRC);
-#endif
+    vboxglEnableOpenGL(pClient);
 
     pName = glGetString(name);
@@ -87,9 +67,5 @@
 end:
 
-#ifdef RT_OS_WINDOWS
-    wglMakeCurrent(NULL, NULL);
-    wglDeleteContext(hRC);
-    ReleaseDC(0, hdc);
-#endif
+    vboxglDisableOpenGL(pClient);
     return rc;
 }
Index: trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.h
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.h	(revision 3707)
+++ trunk/src/VBox/HostServices/SharedOpenGL/vboxgl.h	(revision 3708)
@@ -93,6 +93,7 @@
  * @param   pszFunctionName     OpenGL extension function name
  */
+#ifdef RT_OS_WINDOWS
 bool vboxwglGetProcAddress(char *pszFunctionName);
-
+#endif
 
 /* OpenGL wrappers */
@@ -352,6 +353,8 @@
 void vboxglGetTexImage (VBOXOGLCTX *pClient, uint8_t *pCmdBuffer);
 
+#ifdef RT_OS_WINDOWS
 void vboxwglSwapIntervalEXT (VBOXOGLCTX *pClient, uint8_t *pCmdBuffer);
 void vboxwglGetSwapIntervalEXT (VBOXOGLCTX *pClient, uint8_t *pCmdBuffer);
+#endif
 
 /* after the above */
