After you first create the Canvas3D...

// Set background to pColor
Background vBackground = new Background(new Color3f(pColor));
vCanvas.getGraphicsContext3D().setBackground(vBackground);


And in the preRender method of your extended Canvas3D...

// Clear background to background color
super.getGraphicsContext3D().clear();

Sean


> -----Original Message-----
> From: Raghavendra R [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, July 30, 2002 5:56 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [JAVA3D] Change background color of Canvas3D
> 
> 
> Hi,
> 
> 
> I am calling the repaint method from a method "PrintImage". I 
> have used
> the piece of code in "http://www.j3d.org/faq/capturing.html";. I tried
> setting the Canvas background color and also tried to get Graphics2D
> from the BufferedImage and set the color etc, but still the background
> remains black.
> 
> PrintImage()
> {
> myCanvas.repaint()
> }
> 
> RenderCanvas extends Canvas3D
> {
> postSwap()
> {
>          GraphicsContext3D  ctx = getGraphicsContext3D();
>          Rectangle rect = getBounds() ;
> 
>          Raster ras = new Raster(new Point3f(-1.0f,-1.0f,-1.0f),
> Raster.RASTER_COLOR, 0, 0, rect.width,
>               rect.height, new 
> ImageComponent2D(ImageComponent.FORMAT_RGB,
>                    new BufferedImage(rect.width, rect.height,
> BufferedImage.TYPE_INT_RGB)), null);
> 
>          BufferedImage img = ras.getImage().getImage();
> 
>          try
>          {
>             FileOutputStream out =
>             new 
> FileOutputStream("images/Capture"+postSwapCount_+".jpg");
>             JPEGImageEncoder encoder = 
> JPEGCodec.createJPEGEncoder(out);
>             JPEGEncodeParam param = 
> encoder.getDefaultJPEGEncodeParam(img);
>             param.setQuality(0.9f, false);
>             encoder.setJPEGEncodeParam(param);
>             encoder.encode(img);
>             writeJPEG = false;
>             out.close();
>          }
>          catch (IOException e)
>          {
> 
>          }
> }
> }
> 
> Shouldn't i be setting the background color of the Canvas3D before
> calling the repaint method or can we swap the colors in the 
> BufferedImage?
> 
> Thanks
> Raghav
> 
> 
> David Bourgais wrote:
> 
> > Hi !
> >
> > To change your background color, you sohould use this :
> >
> > float coul1, coul2, coul3; /*In french, coul for couleur (couleur =
> > color in perfect english)*/
> > Background bg = new Background(coul1, coul2, coul3);
> > bg.setCapability(bg.ALLOW_COLOR_READ);
> > bg.setCapability(bg.ALLOW_COLOR_WRITE);
> > bg.setApplicationBounds(/*your BoundingSphere*/);
> > YourScene.addChild(bg);
> > //Changing the background color
> > float a, b, c;
> > bg.setColor(a,b,c);
> >
> > I hope that it will help you.
> >
> > David Bourgais
> >
> > 
> ==============================================================
> =============
> >
> > 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".
> >
> >
> 
> ==============================================================
> =============
> 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".
> 

==========================================================================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