Newsletter sign-up
View all newsletters

Sign up for our Enterprise Java Newsletter

Enterprise Java

3D graphics programming in Java, Part 3: OpenGL

Advantages and disadvantages to Java-to-OpenGL bindings vs. the Java 3D API implementation from Sun

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
It has been a while since our last installment in this series on 3D graphics programming in Java (more on that at the end of this column). Here's a quick refresher on what we were last discussing and where we left off.

In the previous two columns (see Resources), we explored Java 3D. We discussed static content and small scenes, then used larger scene graphs and built interactivity into some basic 3D worlds.

Now that you know a little bit about using Java 3D, it's time to compare and contrast the Java 3D approach to 3D graphics with the leading graphics API contender: OpenGL.

Please note that this article was originally intended to be code-intensive, but the late-breaking decision by Arcane Technologies concerning the Magician binding (see below) necessitated the removal of the code examples. I hope this article's content can be adapted for a future Java-OpenGL binding, as yet unavailable from the OpenGL Consortium.

In any event, I've endeavored to provide all the relevant and useful OpenGL-related references and URLs in the Resources at the end of this column. If you would like to dig further into Java-OpenGL, I strongly recommend that you review these references.

Java-OpenGL comparison with Java 3D

In previous installments on Java 3D, I provided a list of strengths and weaknesses of using Java 3D for graphics applications. Let's reprise that list, but do so by looking at the strengths and weaknesses of Java-OpenGL-based solutions instead of Java 3D-based solutions.

Strengths of using OpenGL (and, by extension and where noted, Java-OpenGL bindings):

  • OpenGL provides a procedural model of graphics
    This closely matches many of the algorithms and methods graphics programmers have used historically. The procedural model is at once intuitive and straightforward for many accomplished 3D graphics aficionados.

  • OpenGL provides direct access to the rendering pipeline
    This is true with any of the various language bindings, including most Java bindings. OpenGL empowers programmers to directly specify how graphics should be rendered. One doesn't just hint and request as with Java 3D, one stipulates.

  • OpenGL is optimized in every imaginable way
    OpenGL is optimized in hardware and software and targeted platforms ranging from the cheapest PCs and game consoles to the most high-end graphics supercomputers.

  • Vendors of every kind of 3D graphics-related hardware support OpenGL
    OpenGL is the standard against which hardware vendors measure their graphics technology, bar none. As Microsoft has joined with SGI in the Fahrenheit initiative, it has become increasingly obvious to many that this is in effect Microsoft's indirect acknowledgment that OpenGL won the API wars for 2D and 3D graphics.


On the other hand, nothing is perfect. OpenGL, and certainly Java-OpenGL bindings, do have some significant shortcomings:

  • The strengths of the procedural approach to graphics programming are simultaneously a weakness for many Java programmers
    For relatively new programmers, many of whom may have received their first formal programming instruction in Java using object-oriented methodologies, OpenGL's procedural method does not mesh well with an object-oriented approach and good engineering practice.

  • Many vendors' OpenGL optimizations are meant to decrease hardware choice
    It is in each vendor's best interest to build proprietary extensions and make proprietary optimizations to sell more of its own hardware. As with all hardware optimizations, you must use accelerator-specific OpenGL optimizations with the understanding that each optimization for one platform diminishes portability and performance for several others. Java 3D's more general-purpose optimizations mostly aim to maximize the portability of Java 3D applications.

  • While C interfaces to OpenGL are ubiquitous, Java interfaces aren't yet standardized and aren't widely available
    Arcane Technologies's Magician product had until recently been in the market to change this portability issue, but with its demise goes much of the cross-platform story for Java-OpenGL, at least at present. More on this below.

  • OpenGL's exposure of the inner details of the rendering process can significantly complicate otherwise simple 3D graphics programs
    Power and flexibility come at the price of complexity. In the fast development cycles of today's technology world, complexity is in and of itself something to be avoided where possible. The old adage about bugs is true: the more lines of code, the more bugs (in general).


As you can see from the pros and cons for OpenGL-based approaches, Java-OpenGL is strong in many of the areas in which Java 3D is weak. OpenGL gives programmers the low-level access to the rendering process that Java 3D explicitly avoids, and OpenGL is currently available on far more platforms than Java 3D (Magician aside). But this flexibility comes with a potential price: programmers have a lot of room to optimize, which conversely means they have a lot of room to screw things up. Java 3D has more built-in optimization and an easier programming model that may prove particularly useful for programmers new to Java, 3D graphics work, or networked and distributed graphics programming.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • For Bill Day's previous Java 3D columns, see the JavaWorld Topical Index http://www.javaworld.com/javaworld/topicalindex/jw-ti-media.html
  • Java-OpenGL bindings and jFree-D
  • The GL4Java binding http://www.jausoft.com/gl4java.html
  • The Jogl Java-OpenGL binding, which is still in beta http://copa.pajato.com/jogl/
  • The Tree Java-OpenGL binding (it's free) http://www.arrakis.es/~aletc/
  • The OpenGL4Java binding http://www.oasis.leo.org/java/classes/graphics/OpenGL4java.dsc.html
  • The JavaOpenGL 1.0a3 binding http://www.palevich.com/3dfx/JavaOpenGL.html
  • JSparrow, an alternative Java binding for OpenGL http://www.will.or.jp/~jsparrow/
  • The jFree-D Java 3D implementation is available from Jean-Christophe Taveau. The site includes a link to download his updated version of Jogl http://spia.freenix.fr/jfd/
  • Want to try your hand at using GNU tools and a free Unix-like development environment for Win32? Check out the open source CygWin development and runtime tools from Cygnus Solutions. Highly recommended http://sourceware.cygnus.com/cygwin/
  • OpenGL tutorial resources
  • "Introduction to OpenGL" (MSDN Online Library) If you're new to OpenGL, this brief provides a good, concise overview (requires free MSDN registration) http://premium.microsoft.com/msdn/library/sdkdoc/opengl/int01_2v58.htm
  • OpenGL Tutorial (Tulane University) Once you understand the very basic concepts from the MSDN overview, take a look at OpenGL code http://www.eecs.tulane.edu/www/Terry/OpenGL/Introduction.html
  • "Windows NT OpenGLGetting Started" (MSDN Online Library) A good, though dated, technical article on Windows-specific OpenGL. This article includes some useful figures illustrating the relationship between OpenGL and other graphics DLLs and the Win32 graphics system (requires free MSDN registration) http://premium.microsoft.com/msdn/library/techart/msdn_opengl9.htm
  • "An OpenGL Update for Game Developers," (Gamasutra magazine, November 1997) An update on OpenGL for Windows that addresses a lot of the out-of-date sections in Microsoft's document. Though this document itself is dated in places (SGI no longer provides a Win32 OpenGL implementation, instead it now works with Microsoft on theirs). The best technical description of OpenGL for Windows I have found online http://www.gamasutra.com/features/programming/112197/opengl_01.htm
  • SGI maintains an excellent OpenGL site, and no, I'm not just saying that because I worked for the company! The site includes links to download a copy of the latest OpenGL specification (1.2), links to standard helper and extension libraries, and much more. http://www.sgi.com/software/opengl/developer.html
  • The OpenGL Consortium resources
  • OpenGL Consortium home page. Stop here first when looking for OpenGL information and resources http://www.opengl.org/Viewpoints/DevView.html
  • The OpenGL Consortium also lists the known Java-OpenGL bindings on its site. Click here to get URLs for the bindings http://www.opengl.org/Documentation/Implementations/Languages.html
  • The Red Book programming reference
  • OpenGL Programming GuideThe Official Guide to Learning OpenGL, Version 1.1 (aka The Red Book), Jackie Neider, Tom Davis, Mason Woo (Addison-Wesley 1997) The definitive OpenGL programming reference http://www1.fatbrain.com/asp/bookinfo/bookinfo.asp?theisbn=0201461382
  • Arcane's Magician resources (while available)
  • Arcane Technologies's Magician site is still active, though much of the content has been removed http://www.arcana.co.uk/products/magician/
  • The Magician documentation. Still available as of this writing, this includes javadocs for the API, as well as a programmer's guide and information on Magician's submission to the OpenGL ARB board for consideration as the basis of the standard OpenGL Java binding http://www.arcana.co.uk/products/magician/docs/
  • Archives of the discussions of the OpenGL Java Binding Subcommittee. List members are currently working to specify a standard Java-to-OpenGL binding for all vendors to be able to provide a consistent Java API for OpenGL graphics. Scroll down to the "Java-OpenGL Working Group," section to read through previous postings http://www.arcana.co.uk/products/magician/mailinglists/index.html
  • Java-OpenGL FAQ. Not convinced that Java bindings to OpenGL are a good choice for your application? Arcane dissects the available options http://www.arcana.co.uk/products/magician/docs/java-opengl-faq.html
  • Other OpenGL, Java 3D, and graphics resources
  • The OpenGL Perl Module site. Do you use Perl for Web hacking or other scripting tasks? If so, you might be interested to know that you can also use OpenGL from within Perl http://www.cs.ualberta.ca/~melax/perl/
  • Tom's Hardware Guide. Want more speed from your OpenGL applications? Upgrade your accelerator card! Tom Pabst has assembled an excellent section on video cards in general and good information on OpenGL accelerators in particular http://www.tomshardware.com/guides/video.html
  • "FahrenheitNo Spontaneous Combustion Here!" Ron Fosner (Gamasutra, April 1998) Have you heard about a new graphics technology called Fahrenheit and wondered where it fits into the OpenGL versus Direct3D and 3D-graphics-in-Java puzzles? Read this third-party assessment for more information and an idea of how it will affect graphical application development in the coming year http://www.gamasutra.com/features/programming/19980410/fahrenheit_01.htm
  • "Exploring the Java 3D API," Travis Bryson (Performance Computing, April 1999) includes all the gory details of the API, and it includes an example application, EarthSim http://www.performancecomputing.com/features/9904f1.shtml
  • SynaPix can be found at http://www.synapix.com