RFR: Update macOS version of the OpenGL sample to match the current state of OpenGL/Glut on Mac [v4]

Ana Maria Mihalceanu duke at openjdk.org
Thu May 30 14:21:36 UTC 2024


> Running the macOS instructions for the [OpenGL sample ](https://github.com/openjdk/jextract/tree/master/samples/opengl) results in failure as Apple discontinued official support for OpenGL (core) and the native `libGL.dylib` doesn't exist anymore. 
> Below is the situation in details:
> 
> * running [compile.sh](https://github.com/openjdk/jextract/blob/master/samples/opengl/compile.sh) or [compilesource.sh](https://github.com/openjdk/jextract/blob/master/samples/opengl/compilesource.sh) will produce Java code that compiles.
> * attempting to run [run.sh](https://github.com/openjdk/jextract/blob/master/samples/opengl/run.sh) will result in error 
> 
> Exception in thread "main" java.lang.ExceptionInInitializerError
> 	at Teapot.main(Teapot.java:75)
> Caused by: java.lang.IllegalArgumentException: Cannot open library: libGL.dylib
> 	at java.base/java.lang.foreign.SymbolLookup.libraryLookup(SymbolLookup.java:314)
> 	at java.base/java.lang.foreign.SymbolLookup.libraryLookup(SymbolLookup.java:266)
> 	at opengl.glut_h_3.<clinit>(glut_h_3.java:58)
> 	... 1 more
> 
> 
> But OpenGL and Glut frameworks are still pre-installed with Apple development tools. This PR fixes the above error by referencing to the OpenGL and Glut frameworks available with Xcode:
> * `jextract` finds the header files via [compile_flags.txt]([[compile.sh](https://github.com/openjdk/jextract/blob/master/samples/opengl/compile_flags.txt)](https://github.com/openjdk/jextract/blob/master/samples/opengl/compile_flags.txt)
> * At runtime, the generated header class finds the shared libraries thanks to providing `-l :/System/Library/Frameworks/GLUT.framework/Versions/Current/GLUT` and `-l -l :/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL` to `jextract` command.
> *  A small side effect: the `Teapot.java` class is updated to use generated `glutDisplayFunc$func` and `glutIdleFunc$func`classes. Generated code varies depending on OpenGL/Glut distribution used. 
> 
> - [x] Tested locally on macOS Sonoma 14.4.1 with JDK 22 and using [jextract binaries](https://jdk.java.net/jextract/).
> - [ ] The code from `Teapot.java` is common for all the operating systems. Additional tests should be done on Windows/Linux.
> 
> **Reviewers**
> [Athijegannathan Sundararajan](https://openjdk.org/census#sundar) (@sundararajana - Committer)

Ana Maria Mihalceanu has updated the pull request incrementally with one additional commit since the last revision:

  Shorten the path to GLUT and OpenGL.

-------------

Changes:
  - all: https://git.openjdk.org/jextract/pull/245/files
  - new: https://git.openjdk.org/jextract/pull/245/files/f7256b6a..a28666a5

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jextract&pr=245&range=03
 - incr: https://webrevs.openjdk.org/?repo=jextract&pr=245&range=02-03

  Stats: 4 lines in 2 files changed: 0 ins; 0 del; 4 mod
  Patch: https://git.openjdk.org/jextract/pull/245.diff
  Fetch: git fetch https://git.openjdk.org/jextract.git pull/245/head:pull/245

PR: https://git.openjdk.org/jextract/pull/245


More information about the jextract-dev mailing list