GLJPanel does not draw the OpenGL content when containing a Swing component

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

GLJPanel does not draw the OpenGL content when containing a Swing component

gouessej
Administrator
Hi!

When I put a JInternalFrame into a GLJPanel, this frame gets rendered but not the OpenGL content. The Java Web Start demos using Java2D/JOGL interoperability work, therefore I will try to write a simple test case to reproduce what is perhaps a regression.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel does not draw the OpenGL content when containing a Swing component

gouessej
Administrator
I'm going to write a bug report as even the simple example of Wikipedia does not work when I replace the GLCanvas by a GLJPanel:

import java.awt.Component;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES1;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLJPanel;
import javax.media.opengl.fixedfunc.GLLightingFunc;
import javax.media.opengl.fixedfunc.GLMatrixFunc;
import javax.media.opengl.glu.GLU;

import com.jogamp.opengl.util.Animator;

public class JOGLTetraHedron implements GLEventListener, KeyListener {
    float rotateT = 0.0f;

    static GLU glu = new GLU();

    static GLJPanel/*GLCanvas*/canvas = new /*GLCanvas*/GLJPanel();

    static Frame frame = new Frame("Jogl 3D Shape/Rotation");

    static Animator animator = new Animator(canvas);

    public void display(GLAutoDrawable gLDrawable) {
        final GL2 gl = gLDrawable.getGL().getGL2();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();
        gl.glTranslatef(0.0f, 0.0f, -5.0f);

        gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
        gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
        gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
        gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);

        gl.glBegin(GL.GL_TRIANGLES);

        // Front
        gl.glColor3f(0.0f, 1.0f, 1.0f);
        gl.glVertex3f(0.0f, 1.0f, 0.0f);
        gl.glColor3f(0.0f, 0.0f, 1.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f);
        gl.glColor3f(0.0f, 0.0f, 0.0f);
        gl.glVertex3f(1.0f, -1.0f, 1.0f);

        // Right Side Facing Front
        gl.glColor3f(0.0f, 1.0f, 1.0f);
        gl.glVertex3f(0.0f, 1.0f, 0.0f);
        gl.glColor3f(0.0f, 0.0f, 1.0f);
        gl.glVertex3f(1.0f, -1.0f, 1.0f);
        gl.glColor3f(0.0f, 0.0f, 0.0f);
        gl.glVertex3f(0.0f, -1.0f, -1.0f);

        // Left Side Facing Front
        gl.glColor3f(0.0f, 1.0f, 1.0f);
        gl.glVertex3f(0.0f, 1.0f, 0.0f);
        gl.glColor3f(0.0f, 0.0f, 1.0f);
        gl.glVertex3f(0.0f, -1.0f, -1.0f);
        gl.glColor3f(0.0f, 0.0f, 0.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f);

        // Bottom
        gl.glColor3f(0.0f, 0.0f, 0.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f);
        gl.glColor3f(0.1f, 0.1f, 0.1f);
        gl.glVertex3f(1.0f, -1.0f, 1.0f);
        gl.glColor3f(0.2f, 0.2f, 0.2f);
        gl.glVertex3f(0.0f, -1.0f, -1.0f);

        gl.glEnd();

        rotateT += 0.2f;
    }

    public void displayChanged(GLAutoDrawable gLDrawable, boolean modeChanged, boolean deviceChanged) {
    }

    public void init(GLAutoDrawable gLDrawable) {
        GL2 gl = gLDrawable.getGL().getGL2();
        gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glClearDepth(1.0f);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
        ((Component) gLDrawable).addKeyListener(this);
    }

    public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
        GL2 gl = gLDrawable.getGL().getGL2();
        if (height <= 0) {
            height = 1;
        }
        float h = (float) width / (float) height;
        gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(50.0f, h, 1.0, 1000.0);
        gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
            exit();
        }
    }

    public void keyReleased(KeyEvent e) {
    }

    public void keyTyped(KeyEvent e) {
    }

    public static void exit() {
        animator.stop();
        frame.dispose();
        System.exit(0);
    }

    public static void main(String[] args) {
        canvas.addGLEventListener(new JOGLTetraHedron());
        frame.add(canvas);
        frame.setSize(640, 480);
        frame.setUndecorated(true);
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                exit();
            }
        });
        frame.setVisible(true);
        animator.start();
        canvas.requestFocus();
    }

    @Override
    public void dispose(GLAutoDrawable gLDrawable) {
        // do nothing
    }
}
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel does not draw the OpenGL content when containing a Swing component

Michael Bien
  Maybe you could even take a look at the junit tests and add a testcase.

However GLJPanel is currently low priority since its by far the slowest
(and most bugy) way of rendering with JOGL.
(http://jogamp.org/wiki/index.php/Jogl_FAQ#Why_using_Swing_for_high_performance_is_not_a_good_idea_.3F)

regards,
michael

On 09/29/2010 01:44 PM, gouessej [via jogamp] wrote:
> I'm going to write a bug report as even the simple example of
> Wikipedia does not work when I replace the GLCanvas by a GLJPanel:
>
[code...]

--
http://michael-bien.com/

Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel does not draw the OpenGL content when containing a Swing component

gouessej
Administrator
Ok I'll do it but I cannot use GIT at work (it has been blocked recently, I don't know how :s). I have already 2 JUnit test cases (about GLU unproject) for some other bugs. When my problem with GIT is solved, I will make some pull requests.

Without GLJPanel, no interoperability with JavaFX 1.3.1 is possible as it is no more possible to mix AWT with JavaFX :(
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel does not draw the OpenGL content when containing a Swing component

Michael Bien
thanks.

regarding blocked git connections. You could try other protocols, e.g. https should work most of the time.

git pull https://gouessej@.../gouessej/jogl.git master

-michael

On 09/30/2010 05:24 PM, gouessej [via jogamp] wrote:
Ok I'll do it but I cannot use GIT at work (it has been blocked recently, I don't know how :s). I have already 2 JUnit test cases (about GLU unproject) for some other bugs. When my problem with GIT is solved, I will make some pull requests.




-- 
http://michael-bien.com/
Reply | Threaded
Open this post in threaded view
|

Re: GLJPanel does not draw the OpenGL content when containing a Swing component

gouessej
Administrator
I tried 6 different protocols without success...
Julien Gouesse | Personal blog | Website