Swing in/over a GLCanvas

I am writing an application using JOGL and my entire UI was developed with it. However, at this point I’m realizing I need a very specific Swing component to use directly within my application. I’ve looked at SWOGL, read all the Java2D/3D mix-in stuff, and even began writing my own system to handle painting of Swing components to TextureRenderer, but all to no avail. The latter showed the most success but I’ve run into several problems attempting to make it work properly.

Are there any solutions available for rendering Swing component in or over a GLCanvas? I would prefer to render in OpenGL directly since that gives me the most capabilities, but I will accept a solution for now that simply shows the component above the OpenGL canvas.

GLCanvas is a heavyweight component and doesn’t work well with swing. Instead you would need to use GLJPanel (it is lightweight) which will work with the Swing components well.

I remember reading something about major performance deficiencies in GLJPanel versus GLCanvas, has that been resolved or if I decide to go this route should I expect to lose significant performance of my application?

You should see a fairly big performance decrease in fps, but this is because it needs to copy back the rendered frames to the swing frame. This penalty should be constant and independent from the complexity of your scene, since it is only related on bandwidth to copy back the frame. So if you have a complex scene, the performance penalty could be swollowable percentage wise.

Just try it out and see if you can live with it. It is the simplest way to get your component.

Btw. what “very specific Swing component” do you need so hard?

One thing regarding the GLJPanel, if you use the Animator then performance will suffer…but if you don’t need the automated updates then you can invoke the display method yourself by cutting out the Animator and that will improve your performance. just a suggestion.

I’m actually writing my own implementation of drawing a hidden AWT Frame to textures, but was hoping someone else had already done this so I didn’t have to. The “very specific” component I need at the moment is JRViewer (a component to view Jasper Reports realtime). Further, I’m going to need the ability to render basic HTML as well. There have been so many components written for Swing it simply opens up a lot of functionality by providing the ability to use Swing components inline.

Can’t you add the GLCanvas to a JPanel and add the JRViewer to the JPanel?
Or am I missing the point here.

Tried that, it doesn’t work

I also would like to be able to do that. In fact what I need is a way to render Swing components in an external OpenGL context. There already a way to render JOGL content in an external context, but rendering swing as perfectly regular OpenGL content is something else I think :wink:

hello , I tried too to draw swing component over jogl.
It was exaclty the same case as yours.

I tried the GLJPanel, I had poor performance in high resolution and compatibilty problem with graphics driver.
So I forgot it.

I decided to use GLCanvas instead, I had two main problems to resolve:
use of textureRenderer but you can’t redraw each components each time ( performance problems)
an event system must displatch events to swing component
They may be other problems…

As GLCanvas is not a container, you can’t add component in it.
I ve found a solution for my problem:

I ve copied all the class GLCanvas in my program with now extends Panel (awt) instead of Canvas (like in JOGL official class).

I can now add swing components in my class GLPanel (now an heavyweight contaainer). If I had a JPanel in the canvas, I draw it manually in an openGL texture using TextureOverlay or TextrureRenedere JOGL classes.(I call method draw in all JPanel components)

It is not a perfect solution bu it is very performant compared to GLJPanel.

You can also have a look at JMonkeyEngine and its package com.jmex.awt.swingui, you can trid the swing demo. I tried it but Id on’t have the time to look at it anymore. It seems to be exactly what wa want, but I didn"t spend enough to test its robustness and performances…

By