"Floating" object on a windows desktop?


I was wondering if it were possible for a desktop application I am writing to display a 3D model “floating” within the desktop … in other words, the window to which jmonkey would be rendering would be a transparent window, and instead of rendering a blank (i.e. by default black) background, anything not part of the model would be rendered with alpha = 0. The app is a Swing app (Swing now supports transparent windows), though if some non-swing window were the only solution that should probably work fine too. It would have to be possible to capture mouse events within the window so that the model (in fact, its window) could be dragged around.


I may be wrong, but chances are that you have to use render to texture, then extract that texture from GPU and then put it on window canwas using winapi.

I’m assuming you mean an “Always on top” window? Meaning no matter what it will be on top of other windows?

Does this have to be JME? You say it’s a Swing App, so this means you would have to rewrite it in JME unless there’s a Swing to JME converter somewhere… I just looked up “Swing 3D” and I thought swing was just 2D (maybe a 3rd-party library?), so I’m curious if this is already in 3D?

JavaFX, I’m pretty sure, has fixed their issue with “AlwaysOnTop” and it should work.

This issue had been going on FOR YEARS, until some people started getting angry about it, and it finally got done at some point I believe fully.

I had created a clock for myself that was always on top, with some functionality. It also was transparent with a cool image.

Also, since it’s already made in Swing, you should be able to convert it directly to JavaFX(if it’s 2D, Idk about 3D stuff with Swing).

You can create and do some nice 3D stuff in JavaFX, but not sure what it’s limits are.

I figured I would mention this, but @prog’s answer is interesting too :smile:



public final void setAlwaysOnTop(boolean value)

Sets the value of the property alwaysOnTop.
Property description:
Defines whether this Stage is kept on top of other windows.
If some other window is already always-on-top then the relative order between these windows is unspecified (depends on platform).

There are differences in behavior between applications if a security manager is present. Applications with permissions are allowed to set “always on top” flag on a Stage. In applications without the proper permissions, an attempt to set the flag will be ignored and the property value will be restored to “false”.

The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

Default value:
JavaFX 8u20


Sorry, perhaps I should have been more explicit.

It’s already a “Swing-with-JME” app, currently the JME 3D content sits
within an LwjglCanvas (standard JME class which encapsulates a
java.awt.Canvas, mapped from a native GL canvas).

The problem I have is in making the scene render to the LwjglCanvas in
such a way that the Canvas.paint() method paints nothing for pixels
which are not displaying part of the model.

What it does now is paint a scene background colour (defaults to black)
for pixels not displaying part of the model, and I couldn’t see any way
to change this or somehow set the scene background to “alpha = 0”.

I have no problems whatever with making swing windows transparent and
always-on-top, the problem is in trying to make LwjglCanvas work in such
a way that the (non-existent) scene background is not painted.


That’s why I say about “render to texture and paint on non-GL canvas”.

If I remember correctly then OpenGL fills the buffer with the background color always. But maybe you can skip this part (you’d need a 32 bit instead of 24 bit render target of course - if it is possible in any way) - I don’t know now.

About the render-to-texture I’m not sure how to get alpha rendered correctly to the texture - maybe you need another buffer target that will receive the “opacity” / “transparency” value and then combine the texture and the buffer. But maybe you can simply render alpha - I don’t know now.

@Momoko_Fan is said to be the graphics specialist of the jME core dev team. Maybe Momoko_Fan knows this?

Alpha is rendered to the buffer already. It used to be a problem when saving screen shots, in fact, because the alpha was getting saved, too. It made the PNG’s look funny when you had semi-transparent stuff.

I think as long as you fill the backgound with alpha=0 then you should be able to keep background transparency.

Edit: actually thinking more about this, I’m 99.9999% sure that’s what I did when rendering my tree atlases in the SimArboreal editor.

It seems that jME3 doesn’t actually pass alpha bits to the canvas, so the driver may choose a pixel format that doesn’t support alpha, i.e. a 24 bits per pixel format.
If that code was modified to set alpha bits properly, and the viewport clear color was set to BlackNoAlpha, you should be able to acheieve what you’re looking for.