1

I’m trying to use JOGL with QtJambi. I’m using code I found in tutorials (some of them are very old) and forums but nothing is displayed. The QGLWidget initialization prevents the window to be displayed. I have no error in the console. The program is running, but there is no window.

Is there something I’m doing wrong ?

Here is my code.

The GLWidget

    public class QtJOGLTestGLWidget extends QGLWidget
{
    protected GLContext context; 
    protected GL gl; 

    public QtJOGLTestGLWidget()
    {
        this(null); 
    }

    public QtJOGLTestGLWidget(QWidget parent)
    {
        super(parent); 
    }

    @Override
    protected void initializeGL()
    {
        GLProfile profile = GLProfile.get(GLProfile.GL2); 
        GLCapabilities glCaps = new GLCapabilities(profile); 
        glCaps.setPBuffer(true); 
        GLDrawableFactory factory = GLDrawableFactory.getFactory(profile); 
        context().makeCurrent(); 
        this.context = factory.createExternalGLContext(); 
        this.context.makeCurrent(); 
        this.gl = this.context.getGL(); 
    }

    @Override 
    protected void resizeGL(int w, int h)
    {
        GL2 gl2 = this.gl.getGL2(); 
        gl2.glViewport(0, 0, w, h);
        gl2.glMatrixMode(GL2.GL_PROJECTION);
        float r = 3.0f / 2.0f;
        gl2.glLoadIdentity();
        gl2.glFrustum(-0.2, 1 * r, -0.2, 1.2, 1, 2000);
    }

    @Override
    protected void paintGL()
    {
        GL2 gl2 = this.gl.getGL2(); 

        gl2.glMatrixMode(GL2.GL_MODELVIEW);
        gl2.glLoadIdentity();

        gl2.glBegin(GL.GL_TRIANGLES);
        {
            gl2.glColor3f(1, 0, 0);
            gl2.glVertex3f(0, 0, -1);
            gl2.glColor3f(0, 1, 0);
            gl2.glVertex3f(0, 1, -1);
            gl2.glColor3f(0, 0, 1);
            gl2.glVertex3f(1, 0, -1);
        }
        gl2.glEnd();
    }
}

The window

    public class QtJOGLTestFrame extends QMainWindow
{
    protected QtJOGLTestGLWidget glWidget; 
    protected QGridLayout gridLayout; 

    public QtJOGLTestFrame()
    {
        this.gridLayout = new QGridLayout(); 
        this.glWidget = new QtJOGLTestGLWidget(this); // This line prevents the window to be displayed 
        this.gridLayout.addWidget(this.glWidget, 0, 0); 

        QWidget widget = new QWidget(); 
        widget.setLayout(this.gridLayout); 
        this.setCentralWidget(widget); 
        this.setWindowTitle("Hello JOGL");
    }
}

Main

    public class QtJOGLTest
{
    public static void main(String[] args)
    {
        QApplication.initialize(args);
        QtJOGLTestFrame frame = new QtJOGLTestFrame(); 
        frame.resize(800, 600); 
        frame.show(); 
        QApplication.execStatic();
    }
}

I'm using the last version of JOGL and Mac OS X Sierra.

Thank you in advance.

Suisei
  • 46
  • 5
  • Please be more accurate, "last" is vague. Do you use JOGL 2.3.2? Please post a SSCCE, not just a small piece of code. – gouessej Dec 21 '16 at 16:35
  • It is indeed the 2.3.2 version of JOGL. – Suisei Dec 21 '16 at 23:50
  • There is all code of my test here. I put -XstartOnFirstThread in the VM arguments of the run configuration. What information can I add ? – Suisei Dec 21 '16 at 23:52
  • At first, storing the GL instance in a protected variable is a bad idea as it can become invalid at any time. Secondly, I think your problem comes from the context creation. You should create the external OpenGL context later but maybe using context().getGL() would be enough. I don't know exactly how QGLWidget works. – gouessej Dec 27 '16 at 16:22
  • You should rather create a new issue and ask the QtJambi maintainers to provide a working example using JOGL 2, this one uses JOGL 1: https://github.com/qtjambi/qtjambi/blob/master/src/java/qtjambi-examples/com/trolltech/demos/opengl/HelloGL.java – gouessej Dec 27 '16 at 16:36
  • Yeah, tutorials and examples I found use JOGL 1. :/ I tried this code with Windows 7 and it works well. There is probably compatibility issues with QtJambi which uses an old version of Qt (4.8.6) and Mac OS X Sierra. I'll contact the current dev team of QtJambi. – Suisei Dec 28 '16 at 20:13
  • Yes it would be nice to know whether the problem comes from JOGL or from QtJambi. – gouessej Dec 29 '16 at 16:13

0 Answers0