fast transparent windows with Ogre - rough draft

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

fast transparent windows with Ogre - rough draft

Post by johnhpus »

Hi guys

A while back I was asked to render an Ogre scene into a transparent window, such that the objects in the scene appeared to float above the desktop. I did a thorough search of the forums and looked around the internet for ideas, and I found the common technique used to achieve that effect. That technique was to render the scene to texture, copy the texture from the GPU into system memory, and then blit that texture onto a layered window. The problem with that technique is that it is brutally slow and as far as I could tell at the time, there was no way around those expensive operations.

A few weeks ago I discovered an alternative technique in an article written by a fellow named Tristan Ward. I have adapted his technique for Ogre, and it allows Ogre to render transparently at full speed without any of the downsides of the old approach. I want to share this information with my fellow Ogre users and to that end I have written an article and example project detailing how to implement this new method of transparent rendering. This is just a draft. I wrote it in one sitting and have barely proof read it. When I have finished I'll add it to the Wiki and also make it available on my website.

If anyone does read it please let me know about errors or problems.

Image

article
http://focusgames.net/Transparent_Windo ... raft_1.pdf

source and binaries
http://focusgames.net/OgreTransparentWindow.7z
Pulas
Halfling
Posts: 61
Joined: Sat Oct 29, 2011 9:39 am

Re: fast transparent windows with Ogre - rough draft

Post by Pulas »

Thanks for sharing! I was looking for this kind of solution. It is really interesting!
User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm
x 3

Re: fast transparent windows with Ogre - rough draft

Post by aguru »

Thanks! I think this should be added to the wiki so this information does not get lost?
User avatar
cybereality
Hobgoblin
Posts: 563
Joined: Wed Jul 12, 2006 5:40 pm
x 12

Re: fast transparent windows with Ogre - rough draft

Post by cybereality »

This looks really interesting. One problem though, when I try this on Windows Vista 32-bit I get a black square (behind the ogre) so it is not transparent for me.
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Re: fast transparent windows with Ogre - rough draft

Post by johnhpus »

Oh, darn, I had really hoped it would work on Vista. I'll have to do some experimentation.

And yeah, this can/will definitely go up on the Wiki. I'll try to proof and polish the article over this week and when it's finished I'll toss it on the Wiki.
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: fast transparent windows with Ogre - rough draft

Post by duststorm »

Interesting.
This technique is specific for windows, but since it works with the OpenGL system I wonder whether it would be possible to use such composite window types on MAC OS and linux too.
Developer @ MakeHuman.org
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Re: fast transparent windows with Ogre - rough draft

Post by johnhpus »

I've done a little reading about achieving this effect on Mac. It seems like there's a way to do it without much trickery, but I don't have much experience coding for Mac and I haven't done any work on it yet.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: fast transparent windows with Ogre - rough draft

Post by Kojack »

This looks really interesting. One problem though, when I try this on Windows Vista 32-bit I get a black square (behind the ogre) so it is not transparent for me.
I had the same thing in windows 7 (a black rectangle behind sinbad). After reading the original article I realised that it was because I use windows classic theme. The technique only works if you have Aero enabled for your desktop. Switching to the default windows 7 theme made it work fine. So it might be your desktop theme settings that are stopping it.
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: fast transparent windows with Ogre - rough draft

Post by duststorm »

Could it be possible that this fast transparent window rendering is a new feature in windows 7 developed for the aero themes? This might be why it gets disabled when disabling the aero themes.
Developer @ MakeHuman.org
User avatar
Zonder
Ogre Magi
Posts: 1168
Joined: Mon Aug 04, 2008 7:51 pm
Location: Manchester - England
x 73

Re: fast transparent windows with Ogre - rough draft

Post by Zonder »

This technique is using the desktop window manager which is only used when aero is enabled. So that is why the black effect when aero disabled as there is no acceleration to the desktop.

It will work on vista as thats when the DWM was created.
There are 10 types of people in the world: Those who understand binary, and those who don't...
User avatar
zarlox
Halfling
Posts: 70
Joined: Tue Apr 19, 2011 12:32 am
Location: Canada
x 2

Re: fast transparent windows with Ogre - rough draft

Post by zarlox »

duststorm wrote:Could it be possible that this fast transparent window rendering is a new feature in windows 7 developed for the aero themes? This might be why it gets disabled when disabling the aero themes.
With the aero theme enabled, the DWM is rendering each window to a D3D texture and then composite the final render for the desktop. Only Vista and 7 when aero is enabled, can use this technique. With classic or basic theme or on windows XP, the GDI blit directly on the screen when rendering the application.

So for windows, you should probably detect if the aero theme is enabled by calling the WIN32 function DwmIsCompositionEnabled() (i think thats the one?).
User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
x 80
Contact:

Re: fast transparent windows with Ogre - rough draft

Post by duststorm »

So the new windows DWM works kind of like Compiz on linux, and propably much like the window compositor on MAC OS too.
For this technique to work you thus need a window compositor or manager that already uses 3D rendering.
This would exclude windows XP, but would be possible to get working on all new operating systems given that users have the proper configuration.

On windows you could probably use the aforementioned DwmIsCompositionEnabled API call and do a fallback to a slower technique if it's not supported or enabled (maybe with a warning message so the user knows what's going on)
Developer @ MakeHuman.org
noorus
Halfling
Posts: 75
Joined: Wed Apr 20, 2011 9:55 pm
Location: Helsinki, Finland
x 3

Re: fast transparent windows with Ogre - rough draft

Post by noorus »

You could fall back on using a layered window if Aero is not available. Layered windows work on every Windows since 2000, and offer a full 8-bit alpha channel as well. They're slower, as they require a move back from video memory to system memory, plus the blit, but you can still achieve hundreds of FPS, although you only need to hit vsync.
Creator of Nice Input Library, for your advanced input needs.
Image
User avatar
johnhpus
Platinum Sponsor
Platinum Sponsor
Posts: 1186
Joined: Sat Apr 17, 2004 2:49 am
x 3

Re: fast transparent windows with Ogre - rough draft

Post by johnhpus »

Yeah, the layered window approach is the original technique I wanted to replace.

Thanks for the tips, insight etc. to everyone who's commented. I will update the article with this information soon, hopefully this weekend.
Post Reply