Monday, August 1, 2011

Exploration of 3d APIs In Java (As of August 2011)

I have always had an interest in the concept of 3d. In the past I've programmed simple environments in both OpenGL and Direct3d, and I even wrote a simple software 3d renderer in BASIC on a Tandy 102 years ago (family vacation growing up; way too many hours in that van). Recently, I've become interested in the idea of bringing 3d to my Java projects, so I've been exploring the options. Here's what I've found so far:


This is definitely the new kid on the block. JavaFX seems to think of itself as a superset of what Flash / Silverlight can do. You can code in pure java, and import your existing java business logic into JavaFX applications. It does run its own rendering, so you could see it as an alternative to Swing / AWT.

Although it's a potentially promising technology, the 3d support is very basic at this point, and not very practical. For example, primitives (such as cubes) are a feature they *may* add for the 2.0 release. (Richard Bair's June 4 reply here.) Plus, embedding it in Swing applications is more of a hack than an available feature, which makes integrating with an existing application a little difficult (and the way to do so may change with future releases).

Java 3D

This is the old mainstay which is used by a number of applications and toolkits. Java 3d has its own container, JCanvas3D, which makes it more difficult to integrate with existing swing component based layouts (though not impossible). It is a scene-graph based library. This means that you create java objects that contain 3d geometry and link them together; then Java 3d does the work to make the scene render. This is very different than a low level library, like OpenGL, where you control the rendering yourself.


This is a community project called Java OpenGL, and is a Reference Implementation of JSR-231. (Look up information on the Java Community Process if you want more information on what this means.) This library lets you write code to control rendering in OpenGL. It is lightweight, unlike Java 3D, so it's easily embedded in existing swing windows in applications. Using this library, you're writing low level code, so it will take a lot more work than using Java 3D in order to get your scene rendering, but you do have a lot more control.


This is an alternative library to JOGL that provides most of the same features as JOGL, along with support for some other things like OpenAL(audio) and OpenCL(allowing use of GPU for CPU type tasks).

The advantages of JOGL and LWJGL (mainly the ability to embed in swing applications and the additional flexibility) make these the best option for me so far. The idea of using OpenGL programming is also exciting to me simply because I like the low level programming. However, I know it's not normally an efficient use of my time. Other people seem to agree, and have created a few libraries that use both JOGL and LWJGL as a base, but add scene-graph type abstraction to speed development.

Which brings me to...


This appears to be the main scene-graph library built on top of one of the low level libraries (LWJGL) that is in common use today. It has 9 years of development under its belt, and has even had a fork or two along the way. It seems to support most of the modern graphics abilities like bump mapping, shadows, parallax mapping and shader programming, etc, all in an easy-to-use quickly digestible form. For my purposes, this library may be a very solid choice.

Adding a jMonkeyEngine canvas to an existing Swing layout also seems to be as simple as adding a regular JComponent. Details are HERE if you're interested.

Special thanks to Erlend Sogge Heggen for corrections on the jMonkeyEngine information above.


I hope this serves as a good introduction to the 3D capabilities and libraries that you might use with Java. This is not a comprehensive list by any means, and I would encourage you to explore more on your own.

Now, a few fun links.

New jMonkeyEngine videos; Thanks Erlend - Older jMonkeyEngine video, from JavaOne 2008 - Ever seen bubblesort in 3d? JOGL - Java 3d, simple house

Please feel free to leave comments if you have anything to add!


Carl.Gould said...

I've heard good things about jMonkey as well - good luck!

Also - Ignition clients launch by default with the -sun.java2d.d3d=false flag, which might be bad for jmonkey. Play with the "Disable Direct3d" and "Disable DirectDraw" flags under system settings in the Gateway to turn this off. said...

Thanks for the mention. Please note however that jMonkeyEngine 3 does not support JOGL out of the box any longer; we're using LWJGL by default now.

Here are two of our most up to date showcase videos:

Beta coming out this August, so be on the look out! :)

Kevin McClusky said...

Thanks Erlend. I've updated the post to reflect that. jME3 in those new videos looks great!

Post a Comment