In my book
Advanced Java Game Programming, I discouraged the use of native code
libraries. Instead I promoted pure Java games that could be deployed both
as Java Web Start desktop applications and as applets embedded in a
webpage.
Recently, however, I developed
Whoola Cyberspace,
a 3D web browser that relies upon the
Java Binding for the OpenGL API
(JOGL)
which includes native code libraries. As this is deployed as a Java Web
Start application, using the native code libraries does not cause any
problems.
As Cyberspace has the ability to display animated 3D scenes in the
XML-based COLLADA
format, the question soon arose as to whether Cyberspace could also be
deployed as an applet to embed 3D scenes within a webpage. Although there
are some commercial tools which provide this capability, to my knowledge
there is no free implementation available in any programming language.
At one time web browsers used to provide built-in VRML support but this is
no longer the case.
I created a
prototype where Cyberspace is deployed as a
signed applet with the native libraries installed on demand but this is
less than satisfactory as it brings up a window requesting that the users
grant the applet full access to their machines.
The goal is to be able deploy Cyberspace as an unsigned applet and still
have it run when the JOGL native libraries are not pre-installed.
The
jGL library is a pure Java implementation of OpenGL created by
Dr. Robin Bing-Yu Chen with an API that is very similar to JOGL.
I recently created a
JOGL-compatible wrapper API for jGL
that I am calling the Java Interface to OpenGL (JIGL) because it lets you
"jiggle" between JOGL-based hardware rendering and jGL-based software
rendering at run-time. Because JIGL adapts jGL to the JOGL API, the same
application code can be used for both deployment environments with and
without access to the JOGL native libraries.
Demo
The applet at the top of this webpage demonstrates JIGL by sequencing
through the JOGL-based animation code in class JiglTest.
If you view the page source for this webpage and examine the applet tag,
you will notice that it includes the JAR files jigl.jar, jgl.jar, and
jogl.jar but not the JOGL native code libraries.
The applet first attempts to use JOGL. In most environments where JOGL
is not pre-installed, it defaults to using jGL as the fallback
implementation.
You can browse the
source code for this demonstration applet from the CVS repository. The
code is under active development and is currently just functional enough
to implement a few examples. The main test application, JiglDemo, displays
animations in both jGL and JOGL in separate frames for a side-by-side
comparison.
If you want to use JIGL in your own source code, you will need the JAR
files
jigl.jar,
jogl.jar, and
jgl.jar.
The
source code for classes JiglApplet, JiglDemo, and JiglTest and the
applet tag embedded in this webpage demonstrate how to use JIGL.
Future
The jGL code library has not been updated since 2003 so much of the JIGL
code is for the purpose of adapting jGL to the current JOGL interface.
The next step is to adapt the JOGL-based scenegraph API
Xith to use JIGL so that
Cyberspace can be deployed both as a Java Web Start desktop application
using OpenGL-based hardware rendering and as an applet embedded in a
webpage using pure Java software rendering. I will then write a tutorial
entitled "How to Embed 3D in Your Webpage" for non-programmers explaining
how they can use the free Open Source tool Cyberspace as an applet.