1

So i have a transparent window with OpenGL 3.3 Context (Windows 8). Whenever I try to draw something it some why draws semi-transparent like this, but I want it opaque:

enter image description here

The fragment shader is

#version 330 core

uniform sampler2D Texture;
uniform sampler2D Texture2;

in vec2 fragTexcoord;
out vec4 color;

void main(void)
{
    color = vec4(0.0, 1.0, 0.0, 1.0);
}

So it just HAS to be green, but it's not;

I've also tried to achieve transparency two ways: with MARGINS and DWM_BLURBEHIND:

    DWM_BLURBEHIND bb = {0};
    bb.dwFlags = DWM_BB_ENABLE;
    bb.fEnable = true;
    bb.fTransitionOnMaximized = 1;
    bb.hRgnBlur = CreateRectRgn(-0, -0, 1000, 1000);


    DwmEnableBlurBehindWindow(_hWnd, &bb);


    SendMessage(_hWnd, WM_PAINT, NULL, NULL);


    UpdateWindow(_hWnd);

    // The second way
    MARGINS margins;
    margins.cxLeftWidth = 0;
    margins.cyTopHeight = 0;
    margins.cxRightWidth = _Options.width;
    margins.cyBottomHeight = _Options.height;
    DwmExtendFrameIntoClientArea(_hWnd, &margins);

But both ways act the same way.

Here I set pixel format:

    PIXELFORMATDESCRIPTOR pfd;
    int format;

    memset(&pfd, 0, sizeof(pfd));
    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags =  PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 24;
    pfd.iLayerType = PFD_MAIN_PLANE;

The window has WS_EX_COMPOSITED and WS_POPUP styles. glClearColor is set to 0.0f, 0.0f, 0.0f, 0.0f.

Any ideas how can I fix this?

Alexey Drozhzhin
  • 193
  • 1
  • 11
  • I'm confused about what you're asking. The green box in your image is fully opaque. It is also pure green. I'm not sure why you say "It has to be green, but it is not" when clearly it is. Additionally, are you trying to achive the green box to be transparent? – Freddy Jul 09 '14 at 14:50
  • Add you might want to look at my "layered" test program of my `wglarb` library. It's a working DWM blurred/transparent example. I know it doesn't really answer your problem, but you might find that this gives you a decent head start. https://github.com/datenwolf/wglarb – datenwolf Jul 09 '14 at 15:44
  • @Freddy This green box isn't opaque, just look at the text on the bottom: when the background is white the alpha of green box suddenly becomes 0. – Alexey Drozhzhin Jul 09 '14 at 17:39

2 Answers2

1

For those who may care: I finally found an answer.

So basically, I did those steps:

1) set the pixel format like this

int format;

memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags =  PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_SUPPORT_COMPOSITION;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 24;
pfd.cAlphaBits = 8;
pfd.cGreenBits = 8;
pfd.cRedBits = 8;
pfd.cStencilBits = 8;
pfd.cBlueBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;

2) then i set blurbehind like this:

DWM_BLURBEHIND bb = {0};
bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
bb.fEnable = true;
bb.fTransitionOnMaximized = 1;
bb.hRgnBlur = CreateRectRgn(0, 0, -1, -1);

I think this tricked the blur 'cause the region is simply wrong.

So then it all looked just like I wanted

enter image description here

Hope this might help someone.

Alexey Drozhzhin
  • 193
  • 1
  • 11
0

Just come to the same problem today. I was trying to make a transparent window by using DwmExtendFrameIntoClientArea then set window border to hidden. When doing that all color except pure white are rendered semi-transparent.

The cause was: I was using a 24-bit color format (red: 8, green: 8, blue: 8, alpha: 0)

DwmEnableBlurBehindWindow function

...

Remarks

The alpha values in the window are honored and the rendering atop the blur will use these alpha values. It is the application's responsibility to ensure that the alpha values of all pixels in the window are correct. ...

source (doc.microsoft.com)

It seems when using 24-bit color mode, the alpha value is treated as 0 (transparent) instead of 255 (opaque). So, just change to 32-bit color mode solves the problem.

RadarNyan
  • 306
  • 1
  • 2
  • 12