Question regarding Windowing

This Question doesn’t really pertain to JOGL or JOGL problems. But its really aimed at the developers of JOGL since I am certain at some point they would have encountered this issue. The question is really this - is it possible to embed a window (created by outside means) within a Java app, given that you have the Window handle.

I have an old OpenGL Visualization tool that I wrote years ago in C++ and I did the Windowing using Glut (since the program is also supposed to be semi-platform independent…it can be recompiled to work under X or Windows). And recently I wrote a JNI interface so that the tool can be used with our new Java based systems. My problem is this, the multiple window thing is causing problems since its not always so easy to control the C++ Window (minimize it, restore it, hide it, bring to front etc.) so that it relates to the system, the window is often obscured and is really just a pain in the ass to the operator sometimes. The end-users have requested (justifiably so) that the external window (the C++ window) be embedded within the application framework (the Java app).

I was hoping somebody here could give me some pointers or advice on how to embed an externally created window in a Java app, because I really don’t have the time to rewrite the whole thing in Java (its quite large +20 000 lines). The best thing I’ve come up with so far is to dump the color buffer to an image, transfer it via NIO onto a java window . But I’m having issues with buffer swapping and flickering.

Any help would be greatly appreciated,
Louis.

Look in the SWT workspace for the AWT/SWT bridge (called SWT_AWT I believe). This allows interoperation of SWT widgets in the AWT and as of JDK 1.5 I believe it works on Windows and X11. Given that your component is just as opaque as an SWT widget would be from the point of view of the AWT I think you should be able to take this bridge apart and make a similar one for your GLUT window. I haven’t personally looked into how it works but am under the impression that it uses the XEmbed extension on X11 and may simply operate on HDCs on Windows. I don’t think it works on Mac OS X. You might find more helpful advice by posting on the javadesktop.org forums.

Thanks Ken. Just a point in the right direction is already a big help.

The SWT/AWT Bridge uses “sun.awt.windows.WEmbeddedFrame” which accepts a Window Handle as an argument in its constructor. It works, but I’m a worried about using a sun packaged class, since that practice is strongly discouraged in the JRE Documentation.

Maybe you could try integrating your native code into an AWT widget. If found a paper that gives a clear example of how to do this. This example creates an AWT Canvas and uses the JAWT interface to interact with it in from the native side. As far as I know JAWT is the only clean way to interact with AWT from native code. It will be a slightly larger effort than simply embedding the window though…