Re: Adding a title to a 3D display

Hi Mike,

> How can I add (non-rotating) text to a VisAD DisplayImplJ3D?
> 
> I have been trying to do this using some modified code that I found on
> the VisAD list.  Here is the code:
> 
>     DisplayRendererJ3D dr
> (DisplayRendererJ3D)display.getDisplayRenderer();
>     VisADCanvasJ3D canvas = dr.getCanvas();
>     J3DGraphics2D g2d = canvas.getGraphics2D();
>     g2d.drawString("My title",50,50);
> 
> This code compiles and everything... but it does not put anything on the
> display... is there something i need to do after adding the text to
> actually update the visAD display?

You need to make your drawString() and other draw calls from
the 'public void renderField(int i)' method of Canvas3D. See
the on-line docs for J3DGraphics2D at:

  
http://java.sun.com/products/java-media/3D/forDevelopers/J3D_1_2_API/j3dapi/index.html

VisAD uses an extension of Canvas3D named visad.java3d.VisADCanvasJ3D,
and you need to extend this class and override its renderField()
method as follows:

  public void renderField(int i) {
    g2d.drawString("My title",50,50);
    // etc
    super.renderField(i);
  }

I have just updated the VisAD server with new constructor
signatures for DisplayImplJ3D that allow you to supply an
argument 'VisADCanvasJ3D c' so you can construct an object
of your class extending VisADCanvasJ3D. The DisplayImplJ3D
constructor you want has signature:

  public DisplayImplJ3D(String name, DisplayRendererJ3D renderer, int api,
                        GraphicsConfiguration config, VisADCanvasJ3D c)
         throws VisADException, RemoteException;

Note that api must be DisplayImplJ3D.JPANEL and your extension
of VisADCanvasJ3D must use the super constructor:

  super(renderer, config);

Get the config as follows:

  GraphicsConfiguration config = VisADCanvasJ3D.getDefaultConfig();

and renderer can be a DisplayRendererJ3D of your choice or just:

  DisplayRendererJ3D renderer = new DefaultDisplayRendererJ3D();

Good luck,
Bill
----------------------------------------------------------
Bill Hibbard, SSEC, 1225 W. Dayton St., Madison, WI  53706
hibbard@xxxxxxxxxxxxxxxxx  608-263-4427  fax: 608-263-6738
http://www.ssec.wisc.edu/~billh/vis.html