Login  Register

Re: Initializing a NEWT Window in Java and Rendering Natively

Posted by Sven Gothel on Mar 05, 2011; 1:30am
URL: https://forum.jogamp.org/Initializing-a-NEWT-Window-in-Java-and-Rendering-Natively-tp2631445p2636431.html

I only can assume sombody has removed the email/message I was just replying to ..
Too bad I can't see who it was - Please PM me .. and/or don't do this, thx.

Here my reply to the removed email ..

On Saturday, March 05, 2011 01:44:04 void-pointer [via jogamp] wrote:

>
> I apologize for not being more precise with my question: by "native
> interoperability," I meant an approach where native code is used to directly
> render onto a surface, such as what is done
> http://download.oracle.com/javase/6/docs/technotes/guides/awt/AWT_Native_Interface.html
> here   using jawti.h. Since I would like to use NEWT instead of Canvas to
> accomplish this, it would not be possible for me to use the jawt.h header to
> accomplish this (if I am wrong here and it is indeed possible, please
> correct me, because I don't see how). Are there any similar functions in the
> headers for the NEWT API which I can use to accomplish this?

got you ..

No need to use C API header for NEWT, it's all exposed in Java
in the NativeSurface interface
  http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/nativewindow/NativeSurface.html

Having an instance of NativeSurface, you only need to:

NativeSurface ns = ..

if ( NativeSurface.LOCK_SURFACE_NOT_READY != ns.lockSurface() ) {
  try {
    long surfaceHandle = ns.getSurfaceHandle();

    .. do somethig with the surface handle,
    .. wheather it is via JNI or not ..
  } finally {
    ns.unlockSurfaceHandle();
  }
}

see
  http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/nativewindow/NativeSurface.html#getSurfaceHandle%28%29
  http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/nativewindow/NativeWindow.html#getWindowHandle%28%29

A NativeSurface is implemented with a NEWT Window,
but alsa with an JAWTWindow (AWT Canvas -> NativeWindow).

In JOGL, we only use the NativeWindow/Surface abstraction to have our code
windowing toolkit agnostic.
  http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/javax/media/nativewindow/NativeWindowFactory.html#getNativeWindow%28java.lang.Object,%20javax.media.nativewindow.AbstractGraphicsConfiguration%29

Using NEWT is of course recommended :)

+++

> @Mr. Bien I should have been more specific when I indicated "GPGPU" - I use
> CUDA to develop my algorithms. Using shaders for general-purpose computation
> would be mind-numbingly painful to say the least 0_o.

Feel free to give JOCL a try!
JOCL is available on jogamp.org as well.

Maybe you can be friends with the idea of using the platform and vendor
independent OpenCL API directly in Java ?
Soon to be available on mobile devices as well.

Of course ... whatever serves you best.

~Sven