Yes, Raffi, that helped!  Thanks for the tip.

Also, thank you, Daniel Selman, David Yazel, John Write and Artur
Biesiadowski for your input.  I've been trying to achive this effect for 3
months -- ever since I posted my question about Overlay Examples in April.

This API is overwhelming sometimes.  Interestingly enough, TYPE_4BYTE_ABGR
slightly changed the appearance of my font.  And I may have simply gotten
lucky on these few runs, but it also removed the necessity to put the label
into an OrderedGroup.  There is no flickering whatsoever now.

For those of you who are also trying to do this, here's my current version
of this method.  I added the label to my textured sphere with these two
lines:
    objSpin.addChild(earthSphere);
    objSpin.addChild(createLabel("Earth", 0.0f, 0.0f, 0.0f));


More work will need to be done.  The size of the BufferedImage should be
calculated based on the length of the string and the font metrics, for
example.  And it should be split up in such a way so that the text can
easily be updated.


   // creates a simple Raster text label (similar to Text2D)
  private Shape3D createLabel( String szText, float x, float y, float z )
  {
    BufferedImage bufferedImage = new BufferedImage( 35, 15,
BufferedImage.TYPE_INT_ARGB );
//    BufferedImage bufferedImage = new BufferedImage( 35, 15,
BufferedImage.TYPE_4BYTE_ABGR );
    Graphics g = bufferedImage.getGraphics( );

//    g.setFont(new Font("Dialog", Font.PLAIN, 12));

//    g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.0f));  // not needed anymore
//    g.fillRect(0, 0, 35, 15);

//    g.setColor(Color.red);  // uncomment these two lines to draw a red box
around the text
//    g.drawRect(0, 0, 34, 14); // perhaps this could indicate Selection

    g.setColor(Color.cyan);
    g.drawString(szText, 2, 12);
    g.dispose();
    ImageComponent2D imageComponent2D = new ImageComponent2D(
ImageComponent2D.FORMAT_RGBA, bufferedImage );

    // create the Raster for the image
    javax.media.j3d.Raster renderRaster = new javax.media.j3d.Raster ( new
Point3f( x, y, z ),

javax.media.j3d.Raster.RASTER_COLOR,
                                                                      0, 0,

bufferedImage.getWidth( ),

bufferedImage.getHeight( ),

imageComponent2D,

                                                                     null );

    Appearance app = new Appearance();
    RenderingAttributes ra = new RenderingAttributes();
    ra.setDepthBufferEnable(false);
    ra.setDepthBufferWriteEnable(false);
    app.setRenderingAttributes(ra);
    TransparencyAttributes ta = new
TransparencyAttributes(TransparencyAttributes.FASTEST, 1.0f);
    app.setTransparencyAttributes(ta);
    return new Shape3D( renderRaster, app );
  }

<<attachment: ss4.jpg>>

Reply via email to