Hi,
I may have found a bug in Java3D and have included a very simple test case.
The problem is this:
I create a buffered image then use the texture loader to get a texture (using the
BY_REFERENCE flag).
I then retrieve the BufferedImage from the ImageComponent2D and draw on it using
Java2D calls. Using one of the consructors of
the texture loader causes errors, another doesn't.
This works fine: TextureLoader texLoader = new TextureLoader(image, "RGBA",
TextureLoader.BY_REFERENCE);
This causes the error: TextureLoader texLoader = new TextureLoader(image, "RGBA",
TextureLoader.BY_REFERENCE, new
java.awt.Component() {});
When I use the 'bad' constructor the following happens:
When I do this a call to fillRect() that exceeds the bounds of the image works fine
(ie any drawing off the image is clipped
correctly) but a call to drawRect() with the same arguments fails (ie the drawing is
not clipped).
I may be using the constrcutor incorrectly but if this was the case then I would
expect consistent results with both drawRect()
and fillRect(). This is not causing me any problems as I am now using the constructor
that works but it looks like a bug.
Cheers,
Brad
___________________OUTPUT________________________
java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at
sun.awt.image.ByteInterleavedRaster.setDataElements(ByteInterleavedRaster.java:529)
at sun.java2d.loops.SolidPixelWriter.writePixel(GeneralRenderer.java:841)
at sun.java2d.loops.GeneralRenderer.doSetRect(GeneralRenderer.java:131)
at sun.java2d.loops.SetDrawRectANY.DrawRect(GeneralRenderer.java:662)
at sun.java2d.pipe.LoopPipe.drawRect(LoopPipe.java:48)
at sun.java2d.pipe.ValidatePipe.drawRect(ValidatePipe.java:40)
at sun.java2d.SunGraphics2D.drawRect(SunGraphics2D.java:2106)
at ClippingTest.drawOnImage(ClippingTest.java:34)
at ClippingTest.<init>(ClippingTest.java:22)
at ClippingTest.main(ClippingTest.java:40)
____________________TEST CLASS___________________
import javax.media.j3d.ImageComponent2D;
import javax.media.j3d.Texture;
import java.awt.image.*;
import java.awt.*;
import com.sun.j3d.utils.image.TextureLoader;
public class ClippingTest {
private int dimension = 512;
public ClippingTest() {
BufferedImage image = new BufferedImage(dimension, dimension,
BufferedImage.TYPE_4BYTE_ABGR);
drawOnImage(image);
//works with this
// TextureLoader texLoader = new TextureLoader(image, "RGBA",
TextureLoader.BY_REFERENCE);
//does not work with this
TextureLoader texLoader = new TextureLoader(image, "RGBA",
TextureLoader.BY_REFERENCE, new java.awt.Component() {});
Texture texture = texLoader.getTexture();
ImageComponent2D imageComponent = (ImageComponent2D)texture.getImage(0);
image = imageComponent.getImage();
drawOnImage(image);
}
private void drawOnImage(BufferedImage image) {
Graphics2D g = image.createGraphics();
g.setColor(new Color(1f, 0f, 0f, 0.5f));
g.fillRect(0, 0, dimension * 2, dimension * 2);
System.out.println("Fill rect greater than bounds ok.");
g.setColor(Color.blue);
g.drawRect(0, 0, dimension * 2, dimension * 2);
System.out.println("Draw Rect greater than bounds ok.");
}
public static void main(String[] args) {
new ClippingTest();
}
}
----------------------------------------------------------------------------
This Email may contain confidential and/or privileged information and is
intended solely for the addressee(s) named. If you have received this
information in error, or are advised that you have been posted this Email by
accident, please notify the sender by return Email, do not redistribute it,
delete the Email and keep no copies.
----------------------------------------------------------------------------
===========================================================================
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".