GL-BufferedImage?

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

GL-BufferedImage?

jeffreportmill
This post was updated on .
What is the best way to effectively get a BufferedImage from OpenGL code?

My best take on it is to create a GLWindow auto drawable and try to move it offscreen, then use AWTGLReadBufferUtil to read from it after display:

[Edit: Update URL:] https://github.com/reportmill/SnapKitGL/blob/main/src/snapgl/RenderImage.java

This has been working for me, with JOGL 2.3.2 and Java 8 on Apple M1. However, I have been having a devil of a time trying to upgrade to Java 11 and JOGL 2.4. GLWindow.create() seems to crash the JRE:

>> A fatal error has been detected by the Java Runtime Environment:
j  java.lang.Class.forName(Ljava/lang/String;)Ljava/lang/Class;+11 java.base@11.0.14
j  com.jogamp.newt.NewtFactory.getCustomClass(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Class;+76
j  jogamp.newt.DisplayImpl.getDisplayClass(Ljava/lang/String;)Ljava/lang/Class;+3
j  jogamp.newt.DisplayImpl.create(Ljava/lang/String;Ljava/lang/String;JZ)Lcom/jogamp/newt/Display;+1

Much of my research ends up with references that are years old. Is JOGL no longer being maintained and updated? Is there a better option for Java + OpenGL? I don't mean to complain - I know it's hard work (beyond my knowledge and skill set). I just thought there would be commercial entities interested in keeping some Java OpenGL solution alive and up to date.

My work doesn't make any money, but I can compile my Java work to the desktop and web. Unfortunately, my OpenGL desktop work is more unreliable than the web:

    SnapCharts: https://reportmill.com/snaptea/SnapCharts/
    (Click on 'show samples' and choose Sample 3D)

SnapCharts 3D

jeff
Reply | Threaded
Open this post in threaded view
|

Re: GL-BufferedImage?

Martin
Hi Jeff,

Could you post the complete JRE core dump to better understand?

In Jzy3D I export screenshots to BufferedImage as you do. I haven't noticed any problem under Java 11 with JOGL 2.4 on Apple M1 (see my compatibility test report here). Note that I use Azul JDK which was the only one available for M1. This avoid relying on Rosetta and will make use of the GL binding for M1 and not for Intel chips. Not sure this will change anything to your problem but worth knowing.

JOGL is maintained "a bit", but we mainly exchange tips for solving issues rather than fix bugs for now.

Other ways I know for working with OpenGL in Java
- LWJGL : I tried a bit 1.5 years ago and encountered lot of issues with the demo programs on macOS so I dropped.
- jGL : is an old implementation of OpenGL 1 in pure Java, without binding to native OpenGL. It works great in Jzy3D for charts with limited number of polygons. You can read how I integrated it in Jzy3D here.
- PanamaGL : is rather POC than a ready to use framework. It uses improvements of Java 17 to invoke native OpenGL. Not useable right now but interesting to watch in the future.

Your web/desktop app is really interesting. What tool do you use to build it?

 
Reply | Threaded
Open this post in threaded view
|

Re: GL-BufferedImage?

gouessej
Administrator
In reply to this post by jeffreportmill
Hello

Have you ever used my suggestions about using --add-opens? Java => 9 requires some changes, it's not specific to JOGL.

I tested SnapCharts, excellent work, it's impressive :)
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL-BufferedImage?

gouessej
Administrator
In reply to this post by jeffreportmill
I think I had a similar problem in JogAmp's Ardor3D Continuation about loading a BufferedImage as a texture. Look at the subprojects named ardor3d-jogl and ardor3d-jogl-awt.

This should be enough, isn't it?
https://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/texture/awt/AWTTextureIO.html#newTextureData(com.jogamp.opengl.GLProfile,java.awt.image.BufferedImage,boolean)
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL-BufferedImage?

gouessej
Administrator
In reply to this post by Martin
It installs the JRE in Node.js:
https://github.com/nvuillam/njre
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: GL-BufferedImage?

jeffreportmill
In reply to this post by Martin
Thank you for this! Sharing your LWJGL experience is helpful - I've been tempted to go off on that tangent, but I was worried it would just lead to a few weeks of frustration. I will also try Azul and see if that helps. I also might give jGL a try.

The secret to my web build is TeaVM (http://teavm.org) and SnapKit (https://github.com/reportmill/SnapKit), a UI kit I built for ReportMill to get to the web. It basically abstracts the platform functionality like Graphics2D and Web CanvasRenderingContext2D (as well as input events, clipboard, drag and drop, etc.). With SnapKit I can implement at a general level, then compile to desktop and/or web. TeaVM is a wonder - I'm a huge fan, and the author is an unheralded hero (IMO). Recently, I've started adding abstraction for 3D. It has a simple platform independent renderer, but then it has an adapter for OpenGL on the desktop and WebGL in the browser.
Reply | Threaded
Open this post in threaded view
|

Re: GL-BufferedImage?

jeffreportmill
In reply to this post by gouessej
Thank you for the suggestion for AWTTextureIO! I plan to dive into textures for the first time next week. Maybe this will provide a new path for rendering that will side step my problem, since I really only need offscreen rendering. I will post an update here after I give it a try.
Reply | Threaded
Open this post in threaded view
|

Re: GL-BufferedImage?

Martin
In reply to this post by jeffreportmill
Thanks for the tip! TeaVM + SnapGL  is a very interesting approach. I'll follow your work :)