[ASK] background transparency

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
phixuannhat
Posts: 15
Joined: Tue Jun 29, 2010 9:52 am

[ASK] background transparency

Post by phixuannhat »

I want to make the background of the Irrlicht view transparent so that I can see through any windows or desktop screen under Irrlicht window.

I modified the tutorial 14 (Win32 window) as followed:

Code: Select all

        ...
         SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
	SetLayeredWindowAttributes(hWnd, RGB(0,255,0), (255 * 50) / 100, LWA_COLORKEY | LWA_ALPHA);

	ShowWindow(hWnd , SW_SHOW);
	UpdateWindow(hWnd);

	// do message queue
	while (device->run())
	{
		driver->beginScene(true, true, SColor(255,0,255,0), videodata);
         ...

but in result, the transparency applies to the whole window, not just the green background


Image

Anyone knows what's wrong?

By the way, is there other ways to make the background transparent without using color-keying? as in there is no background at all, 3D objects are just on top the desktop screen itself like a widget
Last edited by phixuannhat on Mon Aug 16, 2010 9:44 am, edited 1 time in total.
kvakvs
Posts: 30
Joined: Wed Oct 14, 2009 1:50 am
Location: Sweden
Contact:

Post by kvakvs »

This looks like its working as intended (by Windows designers).

To have window border solid, probably you will need to grab desktop picture under your window and then render it before your transparent picture, "simulating" transparence. Of course this will not update the picture if desktop under your window or any underlying window has changed.
phixuannhat
Posts: 15
Joined: Tue Jun 29, 2010 9:52 am

Post by phixuannhat »

Ultimately I want to achieve the effect as below

[photoshopped]
Image

in which you can change the alpha of the background no matter what color it is

any ideas?
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

The only thing I can think of to do it like you want is not irrlicht related. You need to grab the desktop hdc with GetDC(0), then get the pixels around where you want to blend and blend them yourself.
phixuannhat
Posts: 15
Joined: Tue Jun 29, 2010 9:52 am

Post by phixuannhat »

Lonesome Ducky wrote:The only thing I can think of to do it like you want is not irrlicht related. You need to grab the desktop hdc with GetDC(0), then get the pixels around where you want to blend and blend them yourself.
Any sources do I need to look for? coz I'm not familiar with window programming. thanks
d3x0r
Posts: 6
Joined: Mon Dec 14, 2009 1:58 pm

Alpha transparent 3d rendering

Post by d3x0r »

I actually managed to accomplish this with opengl. I almost achieved a rasonable frame rate too, but not really.

As a rendering device, I'm sure that, if it was supported by windows, could be an option; but...

You have to create the window with WS_EX_LAYERED, and really I don't think it works very well except if you create it borderless, and then you would use UpdateLayeredWindowIndirect (vista+) or UpdateLayeredWindow(XP) which takes two HDC's and copies one from your bitmap into the screen. So I created an OpenGL context that rendered just to an hBitmap in a hMemDC that was a memory-only surface... but, this resides in phsyical memory of the system not video memory, so the UpdateLayeredWindow copies from system memory into video memory; and that is VERY slow.

What I tried next was to actually render to an OpenGL context that was off-screen (4000,4000), so the buffer was already on the card, and the opengl could be done in hardware; then I used pbuffers to copy the image into system memory which I could then use UpdateLayeredWindow to output it.

It also ends up that it doesn't work without some post processing in the middle - opengl doesn't generate an alpha attribute (even along the anti-aliased edjdes) so you only end up with color component, which windows blends by addin only - so black isn't black - it's the current background plus nothing; so what you get is a progression to white... because if you have blue and out it over a yellow pixel, it will be 255,255,0 + 0,0,255 = 255,255,255 (white), and it clamps at white.

So this means that if you put your opengl animation over a white window like most explorer windows, you don't see your whites, and black doesn't make it dark, so you end up with a bit of image over the dark text.
Post Reply