c++opengldwm

Transparent OpenGL Window draws weird


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?


Solution

  • 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.