Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback with JNIEnv and binding for JAWT #125

Closed
httpdigest opened this issue Jan 7, 2016 · 7 comments
Closed

Callback with JNIEnv and binding for JAWT #125

httpdigest opened this issue Jan 7, 2016 · 7 comments

Comments

@httpdigest
Copy link
Member

It seems like AWT/Swing is still a very popular solution for doing GUI programming in Java.
As such, the need for a LWJGL 3/AWT/Swing integration often arises.
Therefore, I'd like to revive LWJGL 2's AWTGLCanvas.
The only really headache is to get a hold of the platform-specific window handles of the AWT Canvas object.
It seems that JAWT is still a good solution for it. There are probably other solutions involving only reflection against fields of sun-specific AWT implementation classes (like mentioned by this stackoverflow entry: http://stackoverflow.com/questions/386792/in-java-swing-how-do-you-get-a-win32-window-handle-hwnd-reference-to-a-window).
But if JAWT is going to be used, I'd like to avoid writing native code.
For that, we would need some way to feedback the JNIEnv argument of a JNI function back to Java code by some means of a callback.
This is because I would like to access JAWT with only the platform/struct API exposed by LWJGL 3 with Java. But JAWT needs to be initialized and used through the JNIEnv object.
And in the future it may be useful for other JNI programming in pure Java/LWJGL 3, too, to be able to access the JNIEnv struct.

Could there be a way to callback into Java code with the address of the JNIEnv structure? I know that the JNIEnv argument cannot be cached between different JNI functions, so it must be a callback solution working in the same call stack.

Also, it would be good to have struct bindings for the JAWT core structs, such as JAWT_Win32DrawingSurfaceInfo (and equivalent).

@Spasi
Copy link
Member

Spasi commented Jan 7, 2016

This should be fairly easy to implement. I'll work on it soon.

@dustContributor
Copy link

It seems like AWT/Swing is still a very popular solution for doing GUI programming in Java.

You shouldn't hang out with those people 😝

@JustGregory-zz
Copy link

@dustContributor
Eh, actually if you're programming in Java anyway, using AWT or Swing is an attractive option for me, if at least because it's already part of the JRE/JDK. JavaFX as well, as that's the newer alternative to the older UI methodologies....

@dustContributor
Copy link

Yeah I was implying JavaFX is a better option 😄

@kappaOne
Copy link
Member

kappaOne commented Jan 9, 2016

Implementing AWTGLCanvas with LWJGL3 on Windows and Linux shouldn't be too difficult. The real problem however is implementing it on OSX as there is currently no nice solution. It was really messy getting it working on LWJGL2 and IMO LWJGL3 would be better off just avoiding going down the same path again.

@Spasi Spasi closed this as completed in ea3f3af Jan 10, 2016
@httpdigest
Copy link
Member Author

Thanks a lot! This is a great solution. Especially with the implicit JNIEnv parameter not being exposed in Java.

@Spasi
Copy link
Member

Spasi commented Jan 10, 2016

Yes, handling JNIEnv turned out nice. But there are a couple of issues, that's why I put jawt in the system package (i.e. subject to change in the future):

  • I would have liked to use "JAWT" as the class name, but it clashes with the JAWT struct. Had to come up with a new name (JAWTFunctions).
  • I would like to add support for calling functions in structs directly in the future. Right now you have to get the function pointer from the struct and use the corresponding method in JAWTFunctions to call it. The "DrawingSurface_" prefix is also annoying. (this will probably be done when I add support for C++ bindings)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants