Transparent background color

I would like to have two overlapping viewports with the background colour of the top viewport being transparent…

However, this line:

[java]viewport0.setBackgroundColor(new ColorRGBA(1.0f,0.0f,0.0f,0.0f));[/java]

creates a red background rather than a transparent background even though the alpha parameter is 0.

How do I get jmonkey to use background colors with alpha?


If I remember right you can’t.

The only way to get it transparent is a side-effect of using certain filter, but I can’t remember which one. That’s how I got mine. I think it might be BloomFilter.

But I might be wrong on that and it might have changed.

Yes, sadly I noticed in the ViewPort class code there is actually a bug:

[java]protected final ColorRGBA backColor = new ColorRGBA(0,0,0,0);[/java]

which works anyway because the alpha parameter is ignored. The alpha parameter really should be 1.


Is it possible that this is the compose filter? The documentation for the compose filter says:

This filter compose a texture with the viewport texture. This is used to compose post processed texture from another viewport. the compositing is done using the alpha value of the viewportTexture : mix(compositeTextureColor, viewPortColor, viewportColor.alpha); It's important for a good result that the viewport clear color alpha be 0.

which is very unclear to me but the last sentence implies that it can be used somehow when the “viewport clear color alpha be 0”.

I checked the class I use and it’s a bloom filter on an offscreen rendered texture. That’s how I get mine. But that doesn’t mean the above wouldn’t work. I’d try it if I were you.

You need to disable clearing, not set background color. If you have clearing enabled and a background color with alpha = 0, that’s just clears the framebuffer to be alpha = 0, it won’t let you compose anything because you just cleared what was there to begin with.

See this method:

That did it!


allows for transparent viewports.

Thank you very much for your help.