Multiple viewports in the same JOGL Canvas

Have jReality programming problems or questions? Post them here.
Post Reply
karolemeas
Posts: 5
Joined: Fri 22. Jan 2010, 12:41

Multiple viewports in the same JOGL Canvas

Post by karolemeas » Wed 17. Feb 2010, 10:41

In many contexts it is desirable to have multiple views of the same model or sometimes (as it is in our case) multiple views of multiple models.

I understand that this can be achieved by opening multiple JOGL canvases and sharing the GL context among them to minimize resource consumption. However this approach forces an AWT or Swing-based implementation for GUI (e.g. pop-up menus, toolbars, dialog boxes, etc).

We would prefer to have a full OpenGL implementation for every aspect of the GUI including pop-up elements using a single OpenGL canvas and still have multiple views (in other words OpenGL viewports). Is this possible with jReality?

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Multiple viewports in the same JOGL Canvas

Post by gunn » Wed 17. Feb 2010, 11:42

If I understand your question, you would like to be able to draw into the same GLCanvas (or some kind of GLDrawable) using different viewports, so that for example, the drawing surface is split into four subrectangles, each displaying a different view (for example, different camera) of the same scene graph.

That is currently not possible. The closest thing that is available is cross-eyed stereo mode, in which two viewports are used to draw two views, one for the left eye and one for the right eye. I mention that because it might be possible to expand/generalize the code for this feature, to support what you are proposing.

However, the idea has certain drawbacks which must first be considered. The most serious one concerns the connection to the tool system. For example, in cross-eyed stereo mode picking doesn't work because the picking system isn't "stereo-aware", and picks always against a monocular camera. This is a bug, if you will, in the system which could and should be fixed -- the problem is, stereo is only supported by the JOGL backend and we haven't implemented a clear backend-independent definition of stereo viewing, involving all the different possibilities that are supported. This kind of problem will also effect the usefulness of a multi-viewport JOGL viewer. There would have to be a quite sophisticated layer inserted into the picking system to be able to be able to correctly pick in such a setup.

A further complication would arise if you want to add different tools for different viewports. Tools live in the scene graph, so could not be added easily on a per-viewport basis. If you add a tool for one viewport, you've added it for all. Perhaps one could figure out a way to use the current viewport to sort out whether a tool should be active or not -- not a small task in any case.

The obstacles appear pretty severe. I would recommend that you consider if it's not possible to do what you want within the "1 viewer, 1 view" model which jReality supports. Without knowing more about why that's not feasible it's hard to make suggestions.

One of the reasons you mention for wanting to do this is that you don't want to use AWT or Swing components for GUI. Are you aware of the jReality feature that allows you to "import" such GUI elements into a jReality scene graph as 3D objects? For example, if you run VRViewer (for example by invoking the main() method of de.jreality.plugin.JRViewer with the "-vr" argument), you can see how this works. Double-clicking on the gridded floor in the 3D window toggles display of the GUI elements into and out of the 3D scene. Could this feature lessen the need to display multiple viewports?
jReality core developer

karolemeas
Posts: 5
Joined: Fri 22. Jan 2010, 12:41

Re: Multiple viewports in the same JOGL Canvas

Post by karolemeas » Thu 18. Feb 2010, 16:55

Thank you for your prompt reply. I understand that our requirement cannot be directly addressed by the current design of the jReality framework. However let me explain a little bit further what we wish we could do. We have signle OpenGL Canvas window with multiple viewports in it (same or different "models" in each view) then we want to display a special GUI component (e.g. a transparent pie menu) the extends of which span multiple viewports. This GUI actually applies to more that one viewports that by the way could be small and it is not convenient to limit it within a specific viewport.

We are aware of the capability of jReality to display Swing GUIs within an Open GL Canvas and at this point I should mention that you have the only fully functional implementation of this feature among all 3D frameworks for Java. We really appreciate that!

Kostas

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Multiple viewports in the same JOGL Canvas

Post by gunn » Thu 18. Feb 2010, 22:25

Perhaps then you might be interested in the special JOGL Viewer (GLJPanelViewer) whose GLDrawable is a subclass of JPanel and allows one to render in combination with other Java2D Components. For example, one could pack the viewing components of four of these Viewers into a single parent JPanel or other component, and then render the transparent GUI (as an ordinary Swing or AWT component) over this collection of JPanels using the classes postRender() method. There's a tutorial demo in de.jreality.tutorial.viewer.GLJPanelViewerExample which you might be able to adapt to test out the feasibility of this idea. This would avoid having to develop any new multi-viewport code for the JOGL backend.
jReality core developer

Post Reply