Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / C
Tip/Trick

Transparent OpenGL window

Rate me:
Please Sign up or sign in to vote.
4.43/5 (6 votes)
5 Jan 2011CPOL 39.3K   11   2
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.
C
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.
C
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)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 4 good! Pin
GPUToaster™30-Dec-10 20:09
GPUToaster™30-Dec-10 20:09 
GeneralReason for my vote of 5 May be a way to mix 2D GDI and 3D Op... Pin
jean Davy30-Dec-10 10:55
jean Davy30-Dec-10 10:55 
Reason for my vote of 5
May be a way to mix 2D GDI and 3D OpenGl !

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

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