I"ve done that, here is the code.
Mainly i create a bufferedimage that i fill with a gradient, and then assign this 
image to a Background
node.
Nevertheless, i've submitted a weird thing to Kelvin, and i'm still waiting for his 
response.
Sometimes, the background is white, and mapping does not appear, and if i add a mapped 
object
in the scenegraph, the different textureunit stages i use make the background change 
colors ...
Quite weird. I hope to get an answer for that.

// creating a background texture for the tiles frame.
BufferedImage background = new BufferedImage( w, h, BufferedImage.TYPE_INT_RGB );
Graphics2D g = background.createGraphics();
GradientPaint gp = new GradientPaint( 0,0, new Color( 0.0f, 0.8f, 0.6f ), w-1, h-1, 
new Color( 0.9f, 0.2f, 0.2f ) );
g.setRenderingHint( RenderingHints.KEY_DITHERING,  RenderingHints.VALUE_DITHER_ENABLE 
);
g.setRenderingHint( RenderingHints.KEY_INTERPOLATION, 
RenderingHints.VALUE_INTERPOLATION_BILINEAR );
g.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY 
);
g.setPaint( gp );
g.fillRect( 0,0, w-1, h-1 );
// preparing and adding background
Background bg = new Background( new ImageComponent2D( ImageComponent2D.FORMAT_RGB, 
background ) );
bg.setApplicationBounds( bound );
bg.setImageScaleMode( bg.SCALE_FIT_ALL );
then, add the background node to your scenegraph.. tadaaaaa

Tell me if you also have the bugs...



At 12/02/2003 16:49:00, you wrote:
>Hi All,
>I am trying to create a background with a color gradient.
>I am working with HelloUniverse example for this.
>I am trying to use Background geometry.
>The problem is that when I give the branchgroup , to which the geometry is added as 
>an  argument  to setGeometry method of Background class ,I cannot see the effect.
>The code  is :
>import java.applet.Applet;
>import java.awt.BorderLayout;
>import java.awt.event.*;
>import java.awt.Color;
>import java.awt.GraphicsConfiguration;
>import com.sun.j3d.utils.applet.MainFrame;
>import com.sun.j3d.utils.geometry.ColorCube;
>import com.sun.j3d.utils.universe.*;
>import javax.media.j3d.*;
>import javax.vecmath.*;
>import com.sun.j3d.utils.geometry.Sphere;
>
>public class HelloUniverse extends Applet {
>
>  private SimpleUniverse u = null;
>  Color3f white = new Color3f(1.0f,1.0f,1.0f);
>  Color3f blue = new Color3f(0.0f,0.0f,1.0f);
>
>  private final float[] vertices =
>          { 1.0f,-1.0f,1.0f,
>            1.0f, 1.0f,1.0f,
>           -1.0f, 1.0f,1.0f,
>           -1.0f,-1.0f,1.0f};
>
>
>  public BranchGroup createSceneGraph() {
>
>   BranchGroup objRoot = new BranchGroup();
>
>   TransformGroup objTrans = new TransformGroup();
>   objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
>   objRoot.addChild(objTrans);
>
>   // Create a simple Shape3D node; add it to the scene graph.
>   objTrans.addChild(new ColorCube(0.4));
>
>   Transform3D yAxis = new Transform3D();
>   Alpha rotationAlpha = new Alpha(-1, 4000);
>
>   RotationInterpolator rotator =
>   new RotationInterpolator(rotationAlpha, objTrans, yAxis,
>   0.0f, (float) Math.PI*2.0f);
>   BoundingSphere bounds =
>   new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
>   rotator.setSchedulingBounds(bounds);
>   objRoot.addChild(rotator);
>
>
>   BranchGroup branch = new BranchGroup();
>   branch.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
>   branch.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
>   branch.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
>
>
>   Shape3D rectangle = new Shape3D();
>   rectangle.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
>   rectangle.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
>   rectangle.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
>   rectangle.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
>   rectangle.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE);
>   rectangle.setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_READ);
>   rectangle.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ);
>
>   QuadArray aQuadArray = new 
>QuadArray(4,QuadArray.COORDINATES|QuadArray.NORMALS|QuadArray.COLOR_3);
>   aQuadArray.setCapability(QuadArray.ALLOW_COLOR_READ);
>   aQuadArray.setCapability(QuadArray.ALLOW_COLOR_WRITE);
>   aQuadArray.setCapability(QuadArray.ALLOW_COORDINATE_WRITE);
>   aQuadArray.setCapability(QuadArray.ALLOW_COORDINATE_READ);
>
>
>   aQuadArray.setCoordinates(0,vertices);
>
>
>   Vector3f vector=new Vector3f( 0.0f,0.7f,0.7f);
>   for( int i = 0; i < 4; i++ )
>   {aQuadArray.setNormal( i,vector);}
>
>
>   aQuadArray.setColor(0,white);
>   aQuadArray.setColor(1,white);
>   aQuadArray.setColor(2,blue);
>   aQuadArray.setColor(3,blue);
>
>
>   rectangle.addGeometry(aQuadArray);
>   branch.addChild(rectangle);
>   Background background = new Background();
>   background.setApplicationBounds(bounds);
>   background.setCapability(Background.ALLOW_GEOMETRY_READ);
>   background.setCapability(Background.ALLOW_GEOMETRY_WRITE);
>   background.setGeometry(branch);
>
>   objRoot.addChild(background);
>
>   objRoot.compile();
>   return objRoot;
>
> }
>
>  public HelloUniverse() {
>
> }
>
>  public void init() {
>
>   setLayout(new BorderLayout());
>   GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
>
>   Canvas3D c = new Canvas3D(config);
>   add("Center", c);
>
>   // Create a simple scene and attach it to the virtual universe
>   BranchGroup scene = createSceneGraph();
>   u = new SimpleUniverse(c);
>
>   u.getViewingPlatform().setNominalViewingTransform();
>
>   u.addBranchGraph(scene);
> }
>
>  public void destroy() {
>
>   u.removeAllLocales();
>
> }
>
>  public static void main(String[] args) {
>   new MainFrame(new HelloUniverse(), 256, 256);
> }
>
>
>}
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to