Skip to main content

2D GUI on my screen

4 replies [Last post]
malohkan
Offline
Joined: 2005-02-19

I want to put some boxes (BufferedImage) in the corners of my scene like for status messages. A HUD, of sorts. Here's what I created:

<br />
private class Java3DTextPanel extends TextPanel {</p>
<p>      private BufferedImage image;</p>
<p>      private Raster raster;</p>
<p>      public Java3DTextPanel() {</p>
<p>         super();</p>
<p>         //TODO make the image get bigger if needed</p>
<p>         int width = 200, height = 50;</p>
<p>         image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);</p>
<p>         ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, image);</p>
<p>         buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);</p>
<p>         raster = new Raster(new Point3f(-0.9f, 0.75f, 0.0f), Raster.RASTER_COLOR, 0, 0, width, height, buffer, null);</p>
<p>         raster.setCapability(Raster.ALLOW_IMAGE_WRITE);</p>
<p>      }</p>
<p>      public Raster getRaster() {</p>
<p>         return raster;</p>
<p>      }</p>
<p>      public void setText(String _text) {</p>
<p>         super.setText(_text);</p>
<p>         if(raster!=null) {</p>
<p>                                          System.out.println("text box: " + _text);</p>
<p>            this.paint(image.getGraphics());</p>
<p>            ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, image);</p>
<p>            raster.setImage(buffer);</p>
<p>         }</p>
<p>      }</p>
<p>   }<br />

..and later:
<br />
      Shape3D shape = new Shape3D(trMessageBox.getRaster());</p>
<p>      branchGroup.addChild(shape);<br />

to add it to my scene. I can't get anything to show up. Any idea of what I'm doing wrong?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
malohkan
Offline
Joined: 2005-02-19

OK I tried that, but I still don't see it on my scene. I wonder if it's being covered up by my main 3D scene? Is there a way I can make sure it's in the foreground?

malohkan
Offline
Joined: 2005-02-19

I found the J3DGraphics2D class, and now I'm just using its drawAndFlushImage in my canvas.postRender() method and that has solved my problem. Thanks!

conzar
Offline
Joined: 2003-07-15

Looks like you need to flush your BufferedImage

So in setText();, make sure you do image.flush();

Try that out and post back about it.

conzar
Offline
Joined: 2003-07-15

Also, does anyone have any arguments for using a Raster as opposed to a QuadArray for a HUD?