65.9K
CodeProject is changing. Read more.
Home

Transparent OpenGL window

Dec 30, 2010

CPOL
viewsIcon

40910

Create a transparent window for OpenGL so your 3D shows directly on the desktop.

I saw a query posted regarding this in the Graphics[^] forum and thought it might be a good tip to add here. So we start with creating a layered window: Use the CreateWindowEx[^] function with the dwExStyle parameter set to WS_EX_LAYERED and the dwStyle parameter set to WS_POPUP.
CreateWindowEx(WS_EX_LAYERED,"OpenGL","OpenGL",WS_POPUP, ...);
Set the layered attributes of this window using the SetLayeredWindowAttributes[^] function. Use LWA_COLORKEY as the dwFlags parameter and 0 as the crKey parameter. Now, everything rendered in OpenGL with RGB 000 will be transparent.
SetLayeredWindowAttributes(hWnd, 0, 0, LWA_COLORKEY);
Only thing remaining is to make sure you clear your OpenGL background using 0x00000000 and that you don't have absolute 0 in any of your 3D models!
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
I hope this helps.