views:

236

answers:

3

Rendering contexts usually have a solid color on the background (black or whatever, see the image below):

alt text

I'm wondering if it's possible to setup a window, with no decorations AND with the transparent background, while allowing me to render OpenGL stuff on it.

This would give the illusion that the triangle is floating on the screen. The transparent background should allow you to see the desktop or other applications that might be behind it.

Could you please exemplify with source code?

Platform: Windows (win32 only)

Thank you very much!

+11  A: 

I know this is possible with Windows 7, not sure about earlier versions.

To get rid of the window border you need to remove the WS_OVERLAPPEDWINDOW style from the window and add the WS_POPUP style:

DWORD style = ::GetWindowLong(hWnd, GWL_STYLE);
style &= ~WS_OVERLAPPEDWINDOW;
style |= WS_POPUP;
::SetWindowLong(hWnd, GWL_STYLE, style);

To make the background of the OpenGL window transparent, you will need to use the DwmEnableBlurBehindWindow function:

DWM_BLURBEHIND bb = {0};
bb.dwFlags = DWM_BB_ENABLE;
bb.fEnable = true;
bb.hRgnBlur = NULL;
DwmEnableBlurBehindWindow(hWnd, &bb);

You will also need to specify 0 for the alpha value when calling glClearColor.

glClearColor(0.0f,0.0f,0.0f,0.0f);

Also, when creating your OpenGL context, make sure you allocate an alpha channel.

Now your background should be fully transparent. If you keep the window decorations, then the background will use the Aero blur look and you can adjust the level of transparency using the alpha value in glClearColor.

flashk