Something like this. You have to override Canvas3D.postRender() to make sure the HUD is drawn everytime a frame is rendered. This is supposed to be quite slow, but since drawAndFlushImage was introduced it works good enough.
public class Viewport extends Canvas3D {
private Dimension resolution;
private BufferedImage buffer;
private Graphics2D g2;
private J3DGraphics2D g3;
public Viewport(GraphicsDevice gd,Dimension resolution) {
super(gd.getBestConfiguration(new GraphicsConfigTemplate3D()));
this.resolution=resolution;
buffer=new BufferedImage(resolution.width,resolution.height,BufferedImage.TYPE_4BYTE_ABGR);
g2=buffer.createGraphics();
g3=this.getGraphics2D();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
}
public void postRender() {
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR,0f));
g2.setColor(new Color(0,0,0));
g2.fillRect(0,0,resolution.width,resolution.height);
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1f));
hud.renderFrame(g2,resolution.width,resolution.height);
g3.drawAndFlushImage(buffer,0,0,this);
}
}
public class HUD {
(...)
public void renderFrame(Graphics2D g2,int width,int height) {
// Drawing code goes here
}
}