c++ - 透明的 OpenGL 窗口绘制怪异

标签 c++ opengl dwm

所以我有一个带有 OpenGL 3.3 上下文的透明窗口 (Windows 8)。每当我尝试绘制某些东西时,为什么会像这样绘制半透明的,但我希望它不透明:

enter image description here

片段着色器是

#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);
}

所以它必须是绿色的,但事实并非如此;

我还尝试通过两种方式实现透明度:使用 MARGINS 和 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);

但两种方式的作用相同。

这里我设置了像素格式:

    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;

窗口有 WS_EX_COMPOSITED 和 WS_POPUP 样式。 glClearColor 设置为 0.0f、0.0f、0.0f、0.0f。

有什么办法可以解决这个问题吗?

最佳答案

对于那些可能关心的人:我终于找到了答案。

基本上,我执行了这些步骤:

1) 像这样设置像素格式

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) 然后我像这样设置 blurbehind:

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);

我认为这欺骗了模糊,因为该区域完全错误。

然后一切看起来就像我想要的那样

enter image description here

希望这可能对某人有所帮助。

关于c++ - 透明的 OpenGL 窗口绘制怪异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24656442/

相关文章:

windows - 如何关闭 DwmExtendFrameIntoClientArea?

android - 在 ndk{} DSL 中定义 LOCAL_SRC_FILES

opengl - 在 OpenGL 中绑定(bind)纹理

opengl - 初始化 vao 时出错(glCreateVertexArrays())

opengl - glsl 更新 2D 纹理的特定行

c# - 使用自定义 chrome 和 DWM 时重新绘制窗口标题

c# - 如何将打开的 IE 选项卡显示为 DWM 缩略图?

c++ - UDP套接字recvfrom中的访问冲突读取位置

c++ - Atom Editor 中是否支持 C/C++ 语言的多行注释?

c++ - 使用 C++11 复制构造 boost::shared_ptr 时出错