Runtime switch bewteen orthographic and perspective projections

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

Runtime switch bewteen orthographic and perspective projections

yaqiang
3D rendering class of Plot3DGL which implemented GLEventListener interface in MeteoInfo support both orthographic and perspective projections in "reshape" method (https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java#L4290-L4330). "orthgraphic" is a boolean variable to control it throught the public method "setOrthographic" (https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java#L971-L980). The problem is that I have to resize the plot panel which trigger the "reshape" method to plot the 3D graphics in correct projections after "setOrthographic" method was called.

So I tried to add "updateProjections" method to change the projection (https://github.com/meteoinfo/MeteoInfo/blob/master/meteoinfo-chart/src/main/java/org/meteoinfo/chart/jogl/Plot3DGL.java#L4332-L4367). This method was tried to called in "setOrthographic" method to update and plot graphics in new projections. But I got error of "javax.media.opengl.GLException: No OpenGL context current on this thread" with the code "glu.gluPerspective(45.0f, 1.0f, near, far);" in the "updateProjections" method.

GLUgl2 was also tested but with same error result.

Any help is appreciated!
www.meteothink.org
Reply | Threaded
Open this post in threaded view
|

Re: Runtime switch bewteen orthographic and perspective projections

gouessej
Administrator
Please call this.drawable.invoke​(true, new GLRunnable(){
    public boolean run​(GLAutoDrawable drawable) {
        updateProjections();
        return false;
   }
});

You need a current OpenGL context to make your change work.

Rather call GLU.createGLU(GL).

Please don't use an obsolete version of JOGL, we don't use the javax namespace anymore.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Runtime switch bewteen orthographic and perspective projections

yaqiang
Julien,

Thanks a lot and it works now!




In fact, I am using the latest version of JOGL and the error message was copied from an old subject with similar problem (https://forum.jogamp.org/No-OpenGL-context-current-on-this-thread-td3730697.html).

Regards
Yaqiang
www.meteothink.org
Reply | Threaded
Open this post in threaded view
|

Re: Runtime switch bewteen orthographic and perspective projections

Martin
Hi,

The reason for this exception is that OpenGL is single threaded. The only thread from which the OpenGL context is available by default is the AWT Thread (since the canvas is rendered inside the AWT thread).

When you need an application to perform GL calls outside of the AWT Thread, you have to acquire before your method call and then release the GL context after your method call.

Despite you have a solution, here is my utility to make the GL context available to the current thread :


  public GL acquireGL() {
    return getCurrentGL(canvas);
  }

  public void releaseGL() {
    getCurrentContext(canvas).release();
  }

  /**
   * Get the current GL context of the canvas and make it current.
   *
   * This is usefull when needing to get a GL instance outside of the context of the
   * {@link GLEventListener}.
   */
  public GL getCurrentGL(ICanvas canvas) {
    GLContext context = getCurrentContext(canvas);
    context.makeCurrent();
    return context.getGL();
  }

  public GLContext getCurrentContext(ICanvas canvas) {
    GLAutoDrawable d = ((INativeCanvas) canvas).getDrawable();
    return d.getContext();
  }


I then

GL gl = acquireGL();

gl.glDoSomething();

releaseGL();
Reply | Threaded
Open this post in threaded view
|

Re: Runtime switch bewteen orthographic and perspective projections

yaqiang
Martin,

Thanks for you explanation and suggested solution which are very helpful to me for understanding this issue!

Regards
Yaqiang
www.meteothink.org