JOGL & netbeans gui builder (how to properly show a GLcanvas?)

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

JOGL & netbeans gui builder (how to properly show a GLcanvas?)

dave_xenos
I usually use netbeans GUI builder to layout a JFrame. There is a very old netbeans plugin (http://plugins.netbeans.org/plugin/3260/netbeans-opengl-pack) which adds GLCanvas component to be drag-dropped onto a frame.
But that plugin uses a very old jogl version. There is no plugin for the newer ones.

When using the newer versions of jogl, what is the properway to design using netbeans GUI builder?

I tried to do this by using 'custom-component' feature of netbeans. This is done (my way) by wrapping the com.jogamp.opengl.awt.GLCanvas class in another (empty) class, like this:
public class GLCanvasWrapper extends GLCanvas{
}

Then in the GUI designer I use 'Beans' and provide the wrapper class' full path. This allows me to drag-drop the GLCanvas component on to the JFrame like any other component. But when I run the program, it gives me a blank GLCanvas (it shows what's behind it, not just black).
After some time I found the problem is the code generated by netbeans when you create a JFrame.
When you create a JFrame form in netbeans it automatically adds :
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GLFrame().setVisible(true);
            }
        });
at the 'main' method. I have to remove that invokeLater to make GLCanvas to display normally (just "new GLFrame().setVisible(true);" at main).

Now, removing that generated code makes me feel I did something the wrong way. And indeed sometimes the frame would be displayed with 0 (zero) height!
So, how do i properly show a GLcanvas with this setup?


Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

Xerxes Rånby
The netbeans-opengl-pack is a project last updated December 24, 2009 at
https://kenai.com/projects/netbeans-opengl-pack

The source code still exist but it has not been updated to use JogAmp JOGL
https://kenai.com/projects/netbeans-opengl-pack/sources/glpack-git/show
git://kenai.com/netbeans-opengl-pack~glpack-git

In order to make the plugin work with any JogAmp JOGL release you must clone this git and fix the plugin.
Once the plugin is updated to use JogAmp JOGL we may then host the updated sourcecode for the plugin in our SCM.
http://jogamp.org/git/

When the plugin has a new maintainer then it would be wise to collaborate with the netbeans community to provide a new version to download from the netbeans site.
Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

dave_xenos
Thanks for the answer. But that might be too complicated (having to update an old plugin myself).
Is there any other way to 'manually' utilize netbeans GUI builder with JOGL component? Or are you saying that the proper way to use JOGL component in netbeans GUI builder is by using a plugin?

Perhaps I'll just focus the question on the "java.awt.EventQueue.invokeLater". Here is a new found case:
I tried to completely copy-paste code from a simple project using the old plugin (just a GLCanvas that draws triangle) to a new project which uses new JOGL. The only changes made are the imports :
"javax.media.opengl.GLCanvas" to "com.jogamp.opengl.awt.GLCanvas"
"com.sun.opengl.util.Animator" to "com.jogamp.opengl.util.Animator"
"javax.media.opengl.???" to "com.jogamp.opengl.???"

The code runs fine using the old plugin (obviously). But displays blank (just like explained before) when used with the new JOGL.
Again, when I remove the auto generated "java.awt.EventQueue.invokeLater" at main, the code runs correctly.
What's the problem here? Why old JOGL plugin can use "invokeLater" while the newer ones can't?
Are there any equivalent of "invokeLater" for newer JOGL? Is it truly safe to remove "invokeLater"?

Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

jmaasing
I know nothing about the GLCanvas so I'm mostly guessing but maybe there is a problem with running on the swing thread while the GLContext is 'owned' by the main thread?
Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

gouessej
Administrator
In reply to this post by dave_xenos
This JOGL netbeans plugin is completely outdated. Why not using Netbeans and JOGL without the GUI builder? This plugin relies on a very early version of JOGL 2 (?), even the threading and the drawing has changed a bit in the meantime.

Manipulate an AWT component on the AWT EDT as usual and the AWT GLCanvas is an AWT component. Have you ever looked at our simple examples on Github?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

dave_xenos
The reason I want to use the GUI builder is because I often design a frame that has a lot of component other than the GLCanvas. There may be some jbuttons, jlabels, jtextfields, etc. Using just text code to design the frame is very inefficient.

The old plugin is using JOGL version 1.1.1a actually. That's beyond old, which is why I'm looking for a way to ditch it.

I've read some of JOGL examples and I found a code that do show the JFrame without using invokeLater. So I'm guessing it's fine to remove that "java.awt.EventQueue.invokeLater"?
Although I'm still unsure that one time when I get a frame with zero height. It seems I can't reproduce the case again.
Again, thanks for the replies.
Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

gouessej
Administrator
Actually, even Netbeans 8 Matisse GUI builder produces poor Swing code with tons of warnings. You can override initComponents() to add the JOGL windows and canvas without using the GUI builder, it doesn't prevent you from using it for the rest of the GUI.

In my humble opinion, as nobody wants to maintain the Netbeans OpenGL pack, don't use it.

It's fine to remove java.awt.EventQueue.invokeLater if you're sure you're already on the AWT EDT when you need it.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

gouessej
Administrator
In reply to this post by dave_xenos
Actually, you can call some code after the call of initComponents() in the constructor.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

dave_xenos
Yes, I do add some codes after the call of initComponents(). I think it's fine that way it is now.
Just to make it clear, I'm abandoning that old plugin. I'm not looking for a way to recreate/update the plugin. I design frames using manual code addition together with Matisse now.
That makes me wonder, how do you guys design a frame that has multiple awt/swing component AND JOGL component (GLCanvas or JPanel) in it? Eclipse? Or just textual coding (I kinda feel like a rookie here)?

Anyway, I do the command to create and set visible the JFrame at main() method (which is considered the initial thread?).
Doing these command using java.awt.EventQueue.invokeLater always messes things up (either it freeze for some time or a blank canvas).
Reply | Threaded
Open this post in threaded view
|

Re: JOGL & netbeans gui builder (how to properly show a GLcanvas?)

gouessej
Administrator
Eclipse has a GUI builder too (WindowBuilder) and it's possible to run Matisse in it too (but a bit tricky).

Those tools are useful for the developers who don't want to learn Swing in details or for those who want to spare some time but at the end, it is really a time saver if you understand what is done under the hood. Personally, I prefer coding the UI without those WYSIWYG editors most of the time.

The main thread isn't the AWT EDT. I don't understand why it freezes.
Julien Gouesse | Personal blog | Website