JOGL and swing

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

JOGL and swing

cznlzq
I was trying to make a menu and then when I click the menu, I add the 3d canvas to the frame.

However, it doesn't work as I expected and it freezes there.

Here is the codes. The codes only work when I comment the final GLProfile glp = GLProfile.getDefault(); in the public void actionPerformed(ActionEvent e) function and uncomment the global one.

What's the difference there? Thanks.

By the way, I'm using the rc11 with JAVA 7 in Windows 7.

//=======================================================================
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import com.jogamp.opengl.util.FPSAnimator;

public class SimpleSceneJOGL implements GLEventListener {

    private double theta = 0;
    private double s = 1;
    private double c = 1;

    public static void main(String[] args) {

        //final GLProfile glp = GLProfile.getDefault();
       
        final JFrame frame = new JFrame("AWT Window Test");
        frame.setSize(300, 300);
        JMenu file = new JMenu("File");
        file.setMnemonic('F');
        JMenuItem newItem = new JMenuItem("New");
        newItem.setMnemonic('N');
        file.add(newItem);
        JMenuItem openItem = new JMenuItem("Open");
        openItem.setMnemonic('O');
        file.add(openItem);
        JMenuItem exitItem = new JMenuItem("Exit");
        exitItem.setMnemonic('x');
        file.add(exitItem);
       
      //adding action listener to menu items
        newItem.addActionListener(
            new ActionListener(){
                @Override
                public void actionPerformed(ActionEvent e)
                {
                    System.out.println("New is pressed");
                   
                    final GLProfile glp = GLProfile.getDefault();
                    final GLCapabilities caps = new GLCapabilities(glp);
                    final GLCanvas canvas = new GLCanvas(caps);
                   
                    frame.add(canvas);
                   
                    canvas.addGLEventListener(new SimpleSceneJOGL());

                    FPSAnimator animator = new FPSAnimator(canvas, 60);
                    animator.add(canvas);
                    animator.start();
                   
                    frame.validate();
                    frame.repaint();
                }
            });
       


        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
       
        JMenuBar bar = new JMenuBar();
        frame.setJMenuBar(bar);
        bar.add(file);
       
        frame.setVisible(true);
    }

    @Override
    public void display(GLAutoDrawable drawable) {
        update();
        render(drawable);
    }

    @Override
    public void dispose(GLAutoDrawable drawable) {
    }

    @Override
    public void init(GLAutoDrawable drawable) {
    }

    @Override
    public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    }

    private void update() {
        theta += 0.01;
        s = Math.sin(theta);
        c = Math.cos(theta);
    }

    private void render(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();

        gl.glClear(GL.GL_COLOR_BUFFER_BIT);

        // draw a triangle filling the window
        gl.glBegin(GL.GL_TRIANGLES);
        gl.glColor3f(1, 0, 0);
        gl.glVertex2d(-c, -c);
        gl.glColor3f(0, 1, 0);
        gl.glVertex2d(0, c);
        gl.glColor3f(0, 0, 1);
        gl.glVertex2d(s, -s);
        gl.glEnd();
    }
}
//=======================================================================
Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

gouessej
Administrator
Hi

At first, please use the very latest build of JOGL 2 instead of the RC 11.

Secondly, you can get the GLProfile once for all earlier and not in actionPerformed().
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

cznlzq

Yep, the latest build works.

Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

gouessej
Administrator
You're welcome, thank you for the feedback. I know that some developers are lazy but using obsolete builds is a waste of build. When the developers use very recent builds, they can detect regressions and report them, it is very helpful to fix them. I advise you to use at least the latest release candidate.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

ravenocean
agree with that
你们好!
很高兴跟大家一起学习JOGL
Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

cznlzq
In reply to this post by gouessej
Hi, gouessej

I'm using the release version 2.1.2 now.

And I'm wondering which version of JDK of the 2.1.2 is compiled with.

I didn't find any information about that information from the download package.

Do you know anything about it?

Thanks.




Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

gouessej
Administrator
Please use the latest build of JOGL 2.1.3. Java 1.7 (update 45?) is used but it is still compatible with Java 1.6.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

cznlzq

I have this question because when I'm using JOGL 2.1.2 with Java 1.7 (update 9),
it doesn't work well especially for the 64bits version.

And indeed with a higher Java 1.7 version like update 45, it works great.

So I think it would be better to include the Java compiler information in the jogamp-all-platforms package.



Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

gouessej
Administrator
cznlzq wrote
I have this question because when I'm using JOGL 2.1.2 with Java 1.7 (update 9),
it doesn't work well especially for the 64bits version.
Please be more accurate, you're very vague. I used JOGL 2.x with OpenJDK 1.6 for months without trouble.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

cznlzq
The example I'm using is the one I posted in my first post in this thread.

For JOGL 2.1.2, originally I'm using Java 1.7 (update 9) for the example, it is not stable and it sometime freezes after I click the new button and move my mouse over the frame title (or the position of the minimize/maximize button), more easy to reproduce in 64bits version.

After I updated to the latest Java 1.7 (update 45), everything works great.

Since I used the jogamp-all-platforms.7z downloaded from http://jogamp.org/deployment/
so I asked, for the JOGL 2.1.2, which version of JDK (update number) you guys are using to compile the JOGL libs to generate the jogamp-all-platforms.7z.

I suggest that it's better the information can be added to the package.

Thanks.


Reply | Threaded
Open this post in threaded view
|

Re: JOGL and swing

Sven Gothel
Administrator
On 12/04/2013 04:21 PM, cznlzq [via jogamp] wrote:
> The example I'm using is the one I posted in my first post in this thread.
>
> For JOGL 2.1.2, originally I'm using Java 1.7 (update 9) for the example, it
> is not stable and it sometime freezes after I click the new button and move my
> mouse over the frame title (or the position of the minimize/maximize button),
> more easy to reproduce in 64bits version.
>
> After I updated to the latest Java 1.7 (update 45), everything works great.
So bugs in the AWT/Swing implementation got fixed - great.

>
> Since I used the jogamp-all-platforms.7z downloaded from
> http://jogamp.org/deployment/
> so I asked, for the JOGL 2.1.2, which version of JDK (update number) you guys
> are using to compile the JOGL libs to generate the jogamp-all-platforms.7z.
We build against a JRE RT of Java 1.6 targeting Java6.

See:
<http://jogamp.org/git/?p=gluegen.git;a=blob;f=make/jogamp-env.xml;h=fbf7f5679addd5ffee519e32a115d07345aab6c2;hb=HEAD>

>
> I suggest that it's better the information can be added to the package.

It is orthogonal against which java version we build regarding
bugs occurring in a AWT/Swing implementation.

~Sven



signature.asc (911 bytes) Download Attachment