Click here to Skip to main content
Click here to Skip to main content

Tagged as

Transparent OpenGL window

, 5 Jan 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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 <a href="http://msdn.microsoft.com/en-us/library/ms632680%28VS.85%29.aspx">CreateWindowEx</a>[<a href="http://msdn.microsoft.com/en-us/library/ms632680%28VS.85%29.aspx" target="_blank" title="New Window">^</a>] function with the <i>dwExStyle</i> parameter set to <code>WS_EX_LAYERED</code> and the <i>dwStyle</i> parameter set to <code>WS_POPUP</code>. 
 
CreateWindowEx(WS_EX_LAYERED,"OpenGL","OpenGL",WS_POPUP, ...);
 
Set the layered attributes of this window using the <a href="http://msdn.microsoft.com/en-us/library/ms633540%28v=vs.85%29.aspx">SetLayeredWindowAttributes</a>[<a href="http://msdn.microsoft.com/en-us/library/ms633540%28v=vs.85%29.aspx" target="_blank" title="New Window">^</a>] function. Use <code>LWA_COLORKEY</code> as the <i>dwFlags</i> 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

parths

India India
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 4 good! PinmemberGPUToaster30-Dec-10 21:09 
GeneralReason for my vote of 5 May be a way to mix 2D GDI and 3D Op... Pinmemberjean Davy30-Dec-10 11:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150331.1 | Last Updated 5 Jan 2011
Article Copyright 2010 by parths
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid