How to make screenshot on SWT

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

How to make screenshot on SWT

Paul
Hi everybody.
Since Screenshot class was removed, I found the particular commit which says to use AWTGLReadBufferUtil.readPixelsToBufferedImage method.
So I changed my code in my SWT app accordingly, but I'm getting weird exception

javax.media.opengl.GLException: Should not call this
        at jogamp.opengl.windows.wgl.WindowsExternalWGLContext$Drawable.getSurfaceWidth(WindowsExternalWGLContext.java:133) ~[jogl-all-2.2.4.jar:2.2.4]
        at com.jogamp.opengl.util.awt.AWTGLReadBufferUtil.readPixelsToBufferedImage(AWTGLReadBufferUtil.java:94) ~[jogl-all-2.2.4.jar:2.2.4]
        at com.jogamp.opengl.util.awt.AWTGLReadBufferUtil.readPixelsToBufferedImage(AWTGLReadBufferUtil.java:71) ~[jogl-all-2.2.4.jar:2.2.4]

How should I fix my code?
Thanks
Paul
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

Sven Gothel
Administrator
On 10/24/2014 12:54 PM, Paul [via jogamp] wrote:

> Hi everybody.
> Since Screenshot class was removed, I found the particular commit which says
> to use AWTGLReadBufferUtil.readPixelsToBufferedImage method.
> So I changed my code in my SWT app accordingly, but I'm getting weird exception
>
> javax.media.opengl.GLException: Should not call this
>         at
> jogamp.opengl.windows.wgl.WindowsExternalWGLContext$Drawable.getSurfaceWidth(WindowsExternalWGLContext.java:133)
> ~[jogl-all-2.2.4.jar:2.2.4]
>         at
> com.jogamp.opengl.util.awt.AWTGLReadBufferUtil.readPixelsToBufferedImage(AWTGLReadBufferUtil.java:94)
> ~[jogl-all-2.2.4.jar:2.2.4]
>         at
> com.jogamp.opengl.util.awt.AWTGLReadBufferUtil.readPixelsToBufferedImage(AWTGLReadBufferUtil.java:71)
> ~[jogl-all-2.2.4.jar:2.2.4]
>
> How should I fix my code?
[1] Please file a bug report, so we can fix it.

[2] You may use our SWT GLCanvas

> Thanks
> Paul

Thank you!

~Sven



signature.asc (828 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

Paul
I'll fill the bug report, is it SWT related, or doesn't matter to which category I fill it in?

What do you mean by "use our SWL GLCanvas"?

Thanks a lot for hints

Paul
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

Sven Gothel
Administrator
On 10/24/2014 02:28 PM, Paul [via jogamp] wrote:
> I'll fill the bug report, is it SWT related, or doesn't matter to which
> category I fill it in?

JOGL core

>
> What do you mean by "use our SWL GLCanvas"?

I assume you use SWT w/ our external GLContext,
where the latter exposes this issue.

We also support our own native SWT GLCanvas
as well as NewtCanvasSWT for using NEWT + SWT.

~Sven

>
> Thanks a lot for hints
>
> Paul


signature.asc (828 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

Paul
On which class are you talking about in "We also support our own native SWT GLCanvas"?
Could you point me out to some code with NEWT+SWT?
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

gouessej
Administrator
Hi

He was talking about com.jogamp.opengl.swt.GLCanvas and com.jogamp.newt.swt.NewtCanvasSWT. You can find some examples in the project jogl-demos.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

mjamesupc
This post was updated on .
I am also experiencing this bug, and it is preventing my Eclipse RCP application from exporting a screenshot.   It may or may not be related to how I am using canvases and contexts, but finding the bug filed ( https://jogamp.org/bugzilla/show_bug.cgi?id=1097 ) and discussion here gives me hope that I am using AWTGLReadBufferUtil and BufferedImage correctly.

This is with jogl 2.3.2 and Eclipse SWT GLCanvas, CentOS 6.5 x86_64, and a custom wrapper around GLContext and another for target as GLTarget.


in init():

gl = GLU.getCurrentGL().getGL2();


then in a function     public BufferedImage screenshot():

GLProfile glp = GLProfile.getDefault();
AWTGLReadBufferUtil screenshot = new AWTGLReadBufferUtil(glp, false);
BufferedImage bi = screenshot.readPixelsToBufferedImage(gl, true);



com.jogamp.opengl.GLException: Should not call this
        at jogamp.opengl.x11.glx.X11ExternalGLXContext$Drawable.getSurfaceWidth(X11ExternalGLXContext.java:145)
        at com.jogamp.opengl.util.awt.AWTGLReadBufferUtil.readPixelsToBufferedImage(AWTGLReadBufferUtil.java:94)
        at com.jogamp.opengl.util.awt.AWTGLReadBufferUtil.readPixelsToBufferedImage(AWTGLReadBufferUtil.java:71)
        at com.raytheon.viz.core.gl.internal.GLTarget.screenshot(GLTarget.java:1248)


any insight?



commit from refactoring from jogl 1.1.1 to 2.3.2
https://github.com/Unidata/awips2-core/commit/68392114cfd4ee19a618d3f31c0c6cb404fe6d1e
the screenshot() function:
https://github.com/Unidata/awips2-core/blob/68392114cfd4ee19a618d3f31c0c6cb404fe6d1e/viz/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java#L1204
constructor creating and returning CLCanvas for the application to use
https://github.com/Unidata/awips2-core/blob/68392114cfd4ee19a618d3f31c0c6cb404fe6d1e/viz/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/GLContextBridge.java#L101
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

gouessej
Administrator
There is no version 2.3.2 yet. Please provide a test case to reproduce your bug. X11ExternalGLXContext$Drawable.getSurfaceWidth() shouldn't be called directly, this kind of drawable is used internally just to provide a display connection. Maybe the problem comes from your wrapper around GLContext. Rather use GLContext.getCurrentGL(). I already worked on a similar platform based on Eclipse RCP and SWT with JOGL, I had to port my own code from JOGL 1.1.1a to JOGL 2.0. I have to look a bit deeper at your code.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

gouessej
Administrator
In reply to this post by mjamesupc
Sorry but mixing the obsolete and unmaintained (its maintenance was stopped in 2006, i.e 9 years ago) SWT OpenGL mapping with JOGL is a really bad idea. Moreover, if you abuse of making context current and releasing it, you'll get very bad performance.

Edit.: You can use the AWT GLCanvas with the SWT/AWT bridge (SWT_AWT), the SWT GLCanvas or the NEWT SWT canvas NewtCanvasSWT instead of the obsolete SWT OpenGL canvas provided by SWT.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

mjamesupc
This post was updated on .
gouessej wrote
Edit.: You can use the AWT GLCanvas with the SWT/AWT bridge (SWT_AWT), the
SWT GLCanvas or the NEWT SWT canvas NewtCanvasSWT instead of the obsolete
SWT OpenGL canvas provided by SWT.
I am aware that org.eclipse.swt.opengl.GLCanvas is obsolete, but I am tasked with modifying a large project that has relied on org.eclipse.swt.opengl.GLCanvas, and frankly I'm intimidated by the large number of compilation errors when I change GLCanvas from org.eclipse.swt to com.jogamp.opengl.awt or com.jogamp.opengl.swt.   One particular requirement is being able to cast from  GLCanvas to Canvas, which is possible with  org.eclipse.swt.opengl.GLCanvas but so far not possible with com.jogamp.opengl.awt.GLCanvas.

What should be done with SWT JOGL or AWT JOGL to set and release contexts?    I can't seem to find any documentation about this.  Is this what frame.add( glcanvas ) accomplishes?

I removed GLContextBridge entirely from the project, and am using GLContext.getCurrentGL() instead of GLU.getCurrentGL(), and still see the same errors: screenshot problems and the dreaded "No OpenGL context current on thread" elsewhere when calling TextRenderer getBounds().  

So then I attempted to refactor with com.jogamp.opengl.awt.GLCanvas but find I cannot cast from GLCanvas to Canvas where I need to (which is possible with com.jogamp.opengl.swt.GLCanvas, but other errors prevent the workbench from starting).
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

mjamesupc
Some more questions, and please don't hesitate to point me to documentation that covers this:

in eclipse SWT GLCanvas, we have functions extended from org.eclipse.swt.widgets.Widget and class java.awt.Component such as isDisposed(), getBounds(), getShell(), getClientArea(), addMouseListener() .  These functions are not available for AWT GLcanvas, so I'm curious what the equivalent functions are.  
Reply | Threaded
Open this post in threaded view
|

Re: How to make screenshot on SWT

gouessej
Administrator
In reply to this post by mjamesupc
Which compilation errors do you fail to fix when you use com.jogamp.opengl.swt.GLCanvas? It extends org.eclipse.swt.widgets.Canvas, you only have to replace a few OpenGL related things. You can call getContext() to get the OpenGL context of the canvas. Then, you can call makeCurrent() and release() on this context. However, making an OpenGL context current on different threads is a bit dangerous, it might fail with numerous drivers :s Rather use GLAutoDrawable.invoke() to enqueue OpenGL tasks. It would be even better to perform your OpenGL calls only directly or indirectly in GLEventListener.display(), it would be a lot safer and less error prone.

If you use com.jogamp.opengl.awt.GLCanvas, you'll need to use the bridge I mentioned earlier:
http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fawt%2FSWT_AWT.html
but it won't give you a SWT Canvas.

The AWT GLCanvas extends the AWT Canvas, the same methods are still available. It's similar for the JOGL SWT GLCanvas.
Julien Gouesse | Personal blog | Website