Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, November 2006
QGLWidget and GLU


Message 1 in thread

  Dear all,

  Since my last mail about QGLWidget, I use use this widget with the jogl
wrapper. Everything works fine except when I want use GLU : jogl throw me
the following exception :

QtJambi: Exception pending in native code
Exception in thread "main" javax.media.opengl.GLException: No OpenGL context
current on this thread
    at javax.media.opengl.glu.GLU.getCurrentGL(GLU.java:234)
    at javax.media.opengl.glu.GLU.gluOrtho2D(GLU.java:1184)
    at QtTest.initializeGL(QtTest.java:17)
    at com.trolltech.qt.gui.QWidget.__qt_show(Native Method)
    at com.trolltech.qt.gui.QWidget.show(QWidget.java:1181)
    at QtTest.main(QtTest.java:48)

  Whereas I remove the line that call the GLU method, no exception is thrown
and jogl use the QGLWidget opengl context correctly.

  Is this issue comes from my code or is there a matter between QtJambi and
jogl/GLU to handle the correct opengl context ?

  Laurent.


  code :

  public class QtTest extends QGLWidget {
    private GL gl;
    private GLU glu;
    private int object;
    public void initializeGL() {
        GLContext context = GLDrawableFactory.getFactory()
                .createExternalGLContext();
        this.gl = context.getGL();
        this.glu = new GLU();
        this.glu.gluOrtho2D(0, 1, 0, 1);
        object = makeObject();
    }
    public void resizeGL(int width, int height) {
        this.gl.glMatrixMode(GL.GL_PROJECTION);
        this.gl.glLoadIdentity();
        this.gl.glOrtho(-1, +1, +1, -1, 4.0, 10.0);
        this.gl.glMatrixMode(GL.GL_MODELVIEW);
    }
    public void paintGL() {
        this.gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        this.gl.glLoadIdentity();
        this.gl.glTranslated(0.0, 0.0, -10.0);
        this.gl.glCallList(object);
    }
    int makeObject() {
        int list = this.gl.glGenLists(1);
        this.gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
        this.gl.glNewList(list, GL.GL_COMPILE);
        this.gl.glBegin(GL.GL_POLYGON);
        this.gl.glColor3f(1, 0, 0);
        this.gl.glVertex2f(-0.5f, -0.5f);
        this.gl.glVertex2f(0.5f, -0.5f);
        this.gl.glVertex2f(.5f, .5f);
        this.gl.glEnd();
        this.gl.glEndList();
        return list;
    }
    public static void main(String args[]) {
        QApplication.initialize(args);
        QtTest qtTest = new QtTest();
        qtTest.show();
        QApplication.exec();
    }
}

Message 2 in thread

Hi, Laurent.

This looks like a bug in JOGL to me, although I haven't investigated it 
too thoroughly. GLContext.getCurrent() returns null until you have 
explicitly made JOGL aware of the current context by calling 
makeCurrent() on it. If you explicitly do the makeCurrent() call on the 
context, it should work. Let me know if it doesn't :-)

Laurent Jourdren wrote:

>   public class QtTest extends QGLWidget {
>     private GL gl;
>     private GLU glu;
>     private int object;
>     public void initializeGL() {
>         GLContext context = GLDrawableFactory.getFactory()
>                 .createExternalGLContext();
>         this.gl <http://this.gl> = context.getGL();


context.makeCurrent();

>         this.glu = new GLU();
>         this.glu.gluOrtho2D(0, 1, 0, 1);
>         object = makeObject();
>     }


-- Eskil


Message 3 in thread

On Wednesday 08 November 2006 08:47, Eskil A. Blomfeldt wrote:
> Hi, Laurent.
>
> This looks like a bug in JOGL to me, although I haven't investigated it
> too thoroughly. GLContext.getCurrent() returns null until you have
> explicitly made JOGL aware of the current context by calling
> makeCurrent() on it. If you explicitly do the makeCurrent() call on the
> context, it should work. Let me know if it doesn't :-)
>

Yes, your analysis is correct, but the behaviour is not a bug in JOGL as far 
as I can see, but rather intended behaviour. JOGL cannot tell when a 
particular external OpenGL context is actually active. The whole point of 
these external contexts is to have no coupling with the code that does the 
actual management.

Regards,
Gregor


Message 4 in thread

Gregor Mückl wrote:

>Yes, your analysis is correct, but the behaviour is not a bug in JOGL as far 
>as I can see, but rather intended behaviour. JOGL cannot tell when a 
>particular external OpenGL context is actually active. The whole point of 
>these external contexts is to have no coupling with the code that does the 
>actual management.
>
>  
>
Hi, Gregor.

It may just be a bug in their documentation for 
GLDrawableFactory.createExternalGLContext(), then, as it explicitly says:

"This GLContext object may be used to draw into this preexisting context 
using its GL and GLU objects. [...] The underlying OpenGL context must 
be current on the current thread at the time this method is called. The 
user is responsible for the maintenance of the underlying OpenGL 
context; calls to makeCurrent and release on the returned GLContext 
object have no effect."

I don't see why the createExternalGLContext() couldn't call 
makeCurrent() on the object it returns though, as it always provides the 
current context in the current thread?

-- Eskil