-2

So i want to experimenting with the jextract tool and the Foreign Function and Memory API on OpenGL but im having bad time resolving java.lang.UnsatisfiedLinkError: unresolved symbol: glutInit. It seems like the JVM cannot locate the binaries of the OpenGL library to link the method.I know that you load libraries with the System.load method but the problem is i do not which binaries i must load. The jextract tool is pointed against the .h files and works as expected

`

System.load("/usr/lib/x86_64-linux-gnu/libOpenGL.so.0"); // loads fine but the error persists


try (var s = MemorySession.openConfined()) {
    MemorySegment arc = s.allocate(ValueLayout.JAVA_INT, 0);
    glutInit(arc, arc);
    glutInitDisplayMode(GLUT_SINGLE());
    glutInitWindowSize(400, 300);
    glutInitWindowPosition(100, 100);
    glutCreateWindow(s.allocateUtf8String("Hello World!"));
    MemorySegment callBack = allocate(OpenGLLauncher::displayMe, s);
    glutDisplayFunc(callBack);
    glutMainLoop();
}

`

I assume that i need to load a .so file (im using ubuntu) so i tried manually locating the .so file in /usr/lib i tryied a bunch of them and nothing worked out. I tried searching but nothing was suitable for my case. Here is few thing i tried to follow: 1 2

  • See also [Panama examples](https://hg.openjdk.java.net/panama/dev/raw-file/foreign/doc/panama_foreign.html) Note that Foreign and jextract have changed since the doc was written but it gave me enough to be able to setup OpenGL on Windows. Maybe it will help suggest the missing libraries or step. – DuncG Oct 26 '22 at 10:41

2 Answers2

0

It seems like you do not need to know the exact .so file, but the library name

I used:

System.loadLibrary("GLU"); System.loadLibrary("GL"); System.loadLibrary("glut");

And it worked

  • Note that `jextract -l glut -l GLU -l GL ...` should do this step for you - currently generated into `RuntimeHelper.java`. – DuncG Oct 26 '22 at 11:01
0

You could have a look to project Panama-GL that uses Panama to enable OpenGL for Java. You probably can find a couple of recipes for 3D rendering and Panama configuration there (the issue board provides a kind of Q&A on this, keeping track on former hard bug resolution).

Martin Pernollet
  • 2,285
  • 1
  • 28
  • 39