ecere/gui|gfx: Alpha blended window tweaks (Premultiplied alpha for background, Fixed...
authorJerome St-Louis <jerome@ecere.com>
Fri, 2 Mar 2012 23:39:16 +0000 (18:39 -0500)
committerJerome St-Louis <jerome@ecere.com>
Fri, 2 Mar 2012 23:39:16 +0000 (18:39 -0500)
ecere/src/gfx/drivers/OpenGLDisplayDriver.ec
ecere/src/gui/Window.ec
ecere/src/gui/drivers/XInterface.ec

index 8a0f01f..2895f4b 100644 (file)
@@ -1,4 +1,5 @@
-#define USEPBUFFER
+// We were using PBUFFER for alpha compositing on Linux before, but it does not seem to work, nor be required anymore.
+// #define USEPBUFFER
 
 namespace gfx::drivers;
 
@@ -574,7 +575,8 @@ class OpenGLDisplayDriver : DisplayDriver
          oglSystem.pfd.nVersion = 1;
          oglSystem.pfd.dwFlags = PFD_DRAW_TO_WINDOW /*PFD_DRAW_TO_BITMAP*/ | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
          oglSystem.pfd.iPixelType = PFD_TYPE_RGBA;
-         oglSystem.pfd.cColorBits = 32;
+         oglSystem.pfd.cColorBits = 24;
+         oglSystem.pfd.cAlphaBits = 8;
          oglSystem.pfd.cDepthBits = 24;
          oglSystem.pfd.iLayerType = PFD_MAIN_PLANE;
 
@@ -659,6 +661,8 @@ class OpenGLDisplayDriver : DisplayDriver
                      oglSystem.format = pixelFormat;
                      wglMakeCurrent(null, null);
                      wglDeleteContext(oglSystem.glrc);
+
+                     // *** DescribePixelFormat does not support WGL pixel formats! ***
                      //DescribePixelFormat(oglSystem.hdc, oglSystem.format, sizeof(oglSystem.pfd), &oglSystem.pfd);
                      SetPixelFormat(oglSystem.hdc, oglSystem.format, &oglSystem.pfd);
                      //Log("Successfully set pixel format\n");
index e1dab10..80a95c7 100644 (file)
@@ -2530,7 +2530,13 @@ private:
          if(this == rootWindow)
          {
             if(style.drawBehind || background.a)
+            {
+               int a = background.a;
+               // Premultiply alpha for clear color
+               surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
                surface.Clear(colorBuffer);
+               surface.SetBackground(background);
+            }
          }
          else if(background.a)
          {
@@ -2548,8 +2554,12 @@ private:
             }
             else if(/*style.clearDepthBuffer || */background.a)
             {
+               int a = background.a;
                // surface.Clear((style.clearDepthBuffer ? depthBuffer : 0) | (background.a ? colorBuffer : 0));
+               // Premultiply alpha for clear color
+               surface.SetBackground({ (byte)a, { (byte)(a*background.color.r/255), (byte)(a*background.color.g/255), (byte)(a*background.color.b/255) } });
                surface.Clear(colorBuffer);
+               surface.SetBackground(background);
             }
          }
 
index 0683181..7ff05c9 100644 (file)
@@ -2057,7 +2057,7 @@ class XInterface : Interface
 #endif
       depth = visualInfo ? visualInfo->depth : (window.alphaBlend ? 32 : xSystemDepth);
       visual = visualInfo ? visualInfo->visual : (window.alphaBlend ? FindFullColorVisual (xGlobalDisplay, &depth) : xSystemVisual);
-      // printf("visual: %d, depth: %d\n", visual, depth);
+      // printf("visual: %x, depth: %d\n", visualInfo ? visualInfo->visualid : 0, depth);
 
       if(visual)
       {