Moving Java2D HUD overlay (JOGL + Java 6 style)

Hello everybody, first post, etc, etc.

Basically, I'd like to put real time 2D graphics and animation (ideally using Java2D) on top of a 3D display, HUD style. At the moment I'm drawing to a texture using ImageGraphics, and then updating the texture as required, but this only really gives me two options:

  1. Nail my frame rate massively.
  2. Change the display only rarely.

    Neither of which are ideal. The options I see before me are:

  3. Switch to JOGL for my 3D rendering, and render it into a GLJPanel and just draw my 2D stuff right on top of the 3D scene, just like I would any other JPanel. Not ideal, since JME does the job for me very nicely and I don't fancy having to learn OpenGL.
  4. Starting drawing onto lots of little quads instead of one big one, move these around for animation and only change the ones I need to. I suspect this might also hit my framerate quite hard.
  5. Use JOGL bindings for JME and then just do 1. This seems like best idea, aside from the fact that the JOGL bindings aren't done and there's no current mechanism for getting anything but a Canvas.

    So, I guess what I'm looking for is suggestions for other alternatives, or details on how I could get started on actually doing 3 for myself…


Have you checked out the JMEDesktop class (see TestJMEDesktop, and TestJMEDesktopState for examples of usage).

This will let you use any generic Swing/AWT created component and renders it to the screen in ortho mode onto a quad.

As a side note I noticed that since Java 5.0 you can enable Java2D operations to utilize the OpenGL pipeline for faster rendering just define the following system property as an argument:


I tried this in the TestJMEDesktop class and LWJGL blew up on me:

INFO: Node created.
OpenGL pipeline enabled for default config on screen 0
Jul 26, 2007 4:10:44 PM com.jme.scene.Node attachChild
INFO: Child (my box) attached to this node (RootNode)
Jul 26, 2007 4:10:44 PM com.jme.scene.Node <init>
INFO: Node created.
Jul 26, 2007 4:10:44 PM com.jme.scene.Node <init>
INFO: Node created.
Jul 26, 2007 4:10:45 PM com.jme.scene.Node attachChild
INFO: Child (Desktop) attached to this node (GUI)
Jul 26, 2007 4:10:45 PM uncaughtException
SEVERE: Main game loop broken by uncaught exception
org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
   at org.lwjgl.opengl.Util.checkGLError(
   at org.lwjgl.opengl.Display.swapBuffers(
   at org.lwjgl.opengl.Display.update(
   at com.jme.renderer.lwjgl.LWJGLRenderer.displayBackBuffer(
Jul 26, 2007 4:10:45 PM com.jme.scene.Node detachChildAt
INFO: Child removed.

Does anyone know if LWJGL inherently lets Java2D operations take advantage of the OpenGL pipeline (and doesn't need the -Dsun.java2d.opengl=true.)? and/or is just the fact that it's being rendered in the jME/LWJGL openGL pipeline the same type of optimization?

Why I'm asking is I just read a very interesting blog post by Sun engineer Chris Campbell (Faster Java 2D Via Shaders) saying that they're using OpenGL shaders to speed up Java 2D operations sometimes by factors of 40x to 50x .

I created a quick example of drawing a custom JComponent through a JMEDesktopPane, and it seems to have really good performance (1600 FPS, and the Java2D animated panel is updated and repainted 60 times a second).

I got the idea from another Chris Campbell blog post (Java 2D and JOGL: The Flip Side) describing how to use Java2D custom components in JOGL (he does a much slicker job of pointing it all together, but I bet we could get it looking real nice in jME as well).

jME and Java 2D using JMEDesktopPane

You can also grab the latest version of it in the future straight from my google code SVN: (

Hey, thanks for the quick reply.

My previous experience with JMEDesktop was that animating anything in it really killed the frame rate, but with hindsight this may have been because I tested this by dragging panels around manually and so had to deal with events etc.

This is definitely an improvement over that, but the frame rate still drop as a factor of the the size of the animated component. I transferred your code into my project and tried adding the panel directly to the JDesktop (without the internal frame), made it fill about a third of the screen (approximately the maximum area I'll be animating at any one time) and used alpha blending to remove the background. This takes my frame rate down to about 30 fps, which is far from ideal but isn't intolerable either (ideally I'm looking for around 200fps). I might try drawing to lots of little custom JComponents instead, as this will reduce the screen area I make dirty when I do a redraw, but then I might have cause to try and move these around… which may also slow things right down. I suppose I shall have to see.

JOGL still looks like the best solution (since it can now draw directly into the back buffer of a JPanel), but if I implement this JMEDesktop method it would transfer really easily to a future JOGL type implementation, since in both cases I'm just using Java2D, so thanks very much for the help.

Still open to suggestions though, and would be happy to look at implementing the JOGL bindings. I'll have a look for that in other threads.

let me know if you want to start another JOGL renderer development effort, i'd be interested in helping out.

i know that JOGL has some great support for Java2D plus its basically Sun's official opengl implementation. Also the font rendering to texture TextRender is supposedly great although i guess if you can render Java2D to texture then you can do the same with jME or lwjgl.


So I seem to have solved my problems for the most part by implementing a class which does more or less the same thing as JMEDesktop, but displays my custom graphics and is very careful about which areas of the screen it makes dirty (JMEDesktop seem to be redrawing entire containers when anything in them changes). This seem to be giving me very little slowdown at all, and I can still pull a good 400 fps. Some of my problems could be related to the fact that my cvs checkout is a couple of months old (I can't do it from my lab, so have to carry my whopping great laptop home whenever I want to update), but I'll fix that fairly soon.

I'm contemplating getting a bit deeper into LWJGLImageGraphics to see if I can increase its performance as well. presently it uses a single rectangle to decide the durty areas of the screen, so if you draw a single dot in both the top left and bottom right of the screen the entire thing has to be redrawn. I don't know enough about openGL to be sure, but maybe this can be improved using an array of rectangles and only redrawing the portions which need it.

I still think a JOGL port is a very good idea, since there's a good chance it will become part of the actual JVM in the near future, and that would be a good thing.

Check out

just add a pass and you are there

Its all LWJGL or Jogl, has just about all the controls you would find with swing or SWT, and is the same pattern as SWT

@dougnukem: the tutorial code you're pointing at seems to have disappeared from your googlecode repository.

Where did it disappear to?


To answer why the code disappeared from the SVN more accurately, I actually have no idea why the jME-Tutorials directory is missing on the Google code SVN? I searched the commit logs and don't see any reference to deleting or removing the jME-Tutorials directory from trunk.

Sneaky google....

I don't really know SVN well so I'm trying to see if I can revert it.

It actually disappeared to the innards of an upgraded WordPress . Apparently my Doku Wiki plugin is broken on my blog so that post displays as blank.

I did post it on my wiki though so you can grab the info from there: