Using a JPanel instead of a Canvas

Started by oakes, February 02, 2014, 18:20:09

Previous topic - Next topic

oakes

I'm in a unique situation, because I need to display my LWJGL view inside of a lightweight Swing component (JPanel) rather than a heavyweight AWT component (Canvas). The reason why is that I want to overlay it with a Swing-based text editor widget that has a partially-transparent background. When I use java.awt.Canvas, I can't see it behind the text editor, presumably due to the Swing/AWT mixing issues.

My question is, how would I go about using a Swing-based component instead? I'm aware of GLJPanel, but I don't know how to get LWJGL to use it. The Display.setParent method requires a java.awt.Canvas, so I'm guessing I can't use that class at all. Is there another way to create an OpenGL context with LWJGL that is more flexible? Any guidance is appreciated.

Cornix

As far as I know its completely impossible to mix light-weight components (Swing) and heavy-weight components (OpenGL).
The issue is that the openGL part will be rendered by the operating system while the swing-part will be rendered by the java methods. Because of this you have absolutely no control over drawing priorities and overlapping and such.

Maybe this is no longer the case, but I can remember quite a few threads about this topic a few months ago.

oakes

Have I misinterpreted the purpose of GLJPanel, then? In the link I included, it says it provides OpenGL rendering support in a lightweight Swing component.