Fork me on GitHub

GLG2D OpenGL accelerated Graphics2D

GLG2D is a Graphics2D implementation that uses OpenGL to implement basic Java2D drawing functionality.

See demos for examples of what's possible!

The most recent versions of the Oracle JVM have an OpenGL pipeline to accelerate drawing on some platforms. But the pipeline doesn't use the full power of OpenGL since it doesn't make use of OpenGL's ability to draw primitives directly, like glRectf*(). The Oracle implementation processes most of the Graphics2D calls in Java then sends very primitive commands to the OpenGL system. In addition, Oracle's implementation is not very reliable and will not work on some platforms.

GLG2D takes a different approach. Our goal is to accelerate the most common ways that applications use Java2D drawing. For example, when drawing shapes, we determine which implementation of Stroke is being used and if BasicStroke is used, we use a specialized control path that knows how to handle BasicStroke.

We currently use the fixed function pipeline, with the GL2 profile for most functionality. But a shader implementation is in the pipeline (so to speak). See implementation status for which features are fully implemented.

We use the latest JOGL libraries for the OpenGL implementation.

Get started with GLG2D

You can find the source on GitHub at http://github.com/brandonborkholder/glg2d/.

GLG2D is not in Maven Central yet, but you can point your pom to our repository to fetch the artifacts.

<project>
 ...
 <dependencies>
   <dependency>
     <groupId>org.jogamp.glg2d</groupId>
     <artifactId>glg2d</artifactId>
     <version>0.3-SNAPSHOT</version>
   </dependency>
 </dependencies>
 <repositories>
   <repository>
     <id>glg2d-repo</id>
     <url>http://brandonborkholder.github.com/glg2d/maven2/</url>
   </repository>
 </repositories>
 ...
</project>

Or download directly from here and check out the Javadocs.

It's very easy to get started using GLG2D. As a library, GLG2D is designed to wrap your existing rendering code. If you're using Java2D to render, most likely you're rendering a scene into a some instance of JComponent. In order to render your scene using OpenGL instead of Java2D, just wrap your JComponent inside a GLG2DCanvas.

JComponent renderPane = ...

JFrame frame = new JFrame("My Game");
frame.setContentPane(new GLG2DCanvas(renderPane));
...
And that's it!

Contact

GLG2D is maintained by Brandon Borkholder. You can submit issues on GitHub or send an email to borkhobs (at) gmail.


GLG2D — fast Java2D painting using OpenGL © Brandon Borkholder 2013