Manual render steps

Hi guys,

I would like to make a graphical user interface in Java Swing that shows 3D content. Currently I am using AwtPanelsContext. But there is a technical and conceptual mismatch between the JMonkey engine that is running its own update loop (in a separate thread) and the Swing GUI that is running its own thread to generate events (like button clicks). If possible, I would really prefer staying in Swing instead of switching over to Nifty GUI because my application puts more weight on user interaction with standard Swing components (buttons, text edits, tables, file choosers, …).

Ideally, there would be no JMonkey thread running and I would be able to say “render one frame just now” whenever some Swing event needs it. I have been digging in the JMonkey engine code, and I have discovered that the rendering backends of LWJGL and JOGL all start their own Thread; these threads eventually steer the entire JMonkey main loop (if I understand correctly). Would it be possible to avoid starting such threads and instead have a manual stepping mechanism?

More correctly, I would only need access to sporadic 3D rendering, i.e., I do not need automatically stepped animations, sound, physics nor controller input. Is that possible? Perhaps this is easy, and I just need to better understand the modular design of the JMonkey engine …

I am looking forward to your reactions!

Best,
Tom

For opengl you need to have a single context owning thread, that does all interactions with it.

By adding a semaphore aquire to the update (simpleupdate) you can comtroll the opengl thread, as it will only render one frame then whenever you release taht semaphore.

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Semaphore.html

1 Like

Just do proper threading. Or simply take AWT out of the mix, why use two ways to display stuff on screen anyway?

Say if you have a hardware sensor that gives out measurement data on a separate thread, you have to use SwingUtilities.invokeLater with swing too, just like you have to use app.enqueue in jME.

1 Like

Thanks guys (@EmpirePhoenix and @normen), I will try to do some proper threading with your ideas.

Best,
Tom

1 Like