HUD on top of Canvas3D

Hi,

I’m trying to create a Heads up display for a game on top of the Canvas3D. What I have done so far is create a class that extends Canvas3D and overrides the postRender() method. In postRender() I grab the Graphics object usng this.getGraphics() and draw on it, but it flickers. I think that is because it draws it on the current screen, then it swaps the buffer and calls paint over the HUD. Is there a way in postRender() to grab the buffer and draw to it? What I can do is override paint() and have it draw to an offescreen buffer, draw to the buffer then paint it on, but then it becomes over-buffered. IS there an easier way?

This thread might help:

http://192.18.37.44/forums/index.php?topic=7320.0

Kev

Every really sucessful try at this i knwo of uses textured ploygons in the 3D space aligned parallel to the screen.

I believe the Magicosmn guys made a libnrary they wrote to make thsi easier generally available., Its something you might look into.

We tried that free early xith/magicosm GUI stuff, but as soon as the GUI reached a reasonable size, performance broke down. Those days we managed to create a radar screen 64x64 in size. 65x65 (which in fact is the same as 128x128) already cut performance significantly…

j3d.org has something similar IIRC.

The only problem I’ve had with this approach is that things getting close to the camera can collide with the UI panes. I’ve not really investigated this in depth yet, though- does anyone have a good workaround for it?

Herkules- did you try splitting up your panes into several different small squares rather than using a single big one?

On the collision, what if yo uset your near clkip plane to the same depth as your HUD?

Endolf’s newdawn HUD stuff attempts to do the breaking down of the surfaces for you I believe. It also uses some forumla provided by StarFire Research to calculate where the HUD plane should exist to prevent the collision issue (at least as far as I recall).

http://www.newdawnsoftware.com/resources/earlyaccess.html

Kev

The xith lib did that. Nevertheless … as soon as it grew bigger than 64x64, there was a performance breakdown.

I have had much success with the extension of Canvas3D, overriding postRender(). I have also solved the flickering issue:

class DrawOnCanvas3D extends Canvas3D
{
private GraphicsContext3D gc3d;
private J3DGraphics2D j3dg2d;
private int width = 512, height = width;
private BufferedImage bufim;
private Graphics2D g2d;

public DrawOnCanvas3D(GraphicsConfiguration gc)
{
    super(gc);
    bufim = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    g2d = bufim.createGraphics();
    j3dg2d = this.getGraphics2D();
    gc3d = this.getGraphicsContext3D();
}

public void postRender()
{

    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR, 0.0f));
    g2d.setColor(Color.BLACK);
    g2d.fillRect(0,0,width,height);
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    g2d.setColor(Color.WHITE);

/---->
g2d.drawingStuffHappensHere(…)
<----
/

    j3dg2d.drawAndFlushImage(bufim, 0, 0, this);
}

}