2011年8月30日 星期二

Using JAWT implements Web3D

JAWT ( Java Abstract Window Toolkit )
    Java use it to define the different OS's create window layer, we get this window's handle by JAWT. In this approach we can draw 3D objects presented on the window's handle, which is by GPU acceleration.


JNI ( Java Native Interface )
   Java can upload native program's library ( etc: *.dll ). Call the native function defined in this linked library.



STEPS:
  1. Design your java code to be Applet style, You can adopt eclipse SWT(standard widget toolkit) to support JAWT canvas easier.
  2. Define the native interface in your *.java file. Like this:
       // native entry point for Painting
        public native void paintOpenGL();

        // native entry point for enabling OpenGL calls.
        public native void initializeOpenGL();

        // native entry point for disabling OpenGL calls.
        public native void cleanupOpenGL();
  3. Load library in the java:
        System.loadLibrary("openglAWT");
  4. Compare your java code
    javac to generate .class files.
    javah to generate the c++ header (*.h)
  5. Open your c++ dll project, include the generated header. Implement the native interfaces to let JNI can call these function correctly. Build it, and generate the dll file.

    ***Until this step. If you just want to develop a standalone environment, you have let JAWT and JNI achieve 3D present. However, we aim to move it on browser, so we still some work need to be completed.

  6. Pack your *.dll, *.class, and assets to *.jar files.
         jar cvf native.jar *.dll
        jar cvf j3d.jar *.class
  7. Because your application is on web, you need to certify them is been trusted. We produce the certification file.
    create a keystore keytool -genkey -keystore myKeystore -alias myselfcreate a self-signed certificate keytool -selfcert -alias myself -keystore myKeystore
  8.  Every *.jar file needs to be signed:
       
    jarsigner.exe -keystore myKeystore -storepass    password jarfile.jar myself 
  9. Define your html file
        param name="jnlp_href" value="ellison3D.jnlp"
  10. Describe JNLP param.
        jar href="./commonjar/j3D.jar" main="true" /
       nativelib href="./commonjar/swt.jar"/
       nativelib href="./commonjar/native.jar"/

  11. Put your JNLP near the html file
     
Result: 
  • Direct3D in browsers(IE, Chrome, Firefox)
  • OpenGL in browsers(IE, Chrome, Firefox)


Reference:  

    沒有留言:

    張貼留言