Hi,

I am trying to create a grayscale texture, which I am generating,
on a rectangle and I have some questions.  I am currently getting:

Exception occurred during event dispatching:
  java.awt.image.RasterFormatException:
         DataBuffer for ByteComponentRasters must only have 1 bank.

The code looks like this:

// I have a byte array with the gray values
//     int xsize, ysize;  (set to the size of the image)
//     int length = xsize * ysize;
//     byte [] byte_array = new byte [length];
//     byte_array values are set

    DataBufferByte db = new DataBufferByte(byte_array, length);

    BufferedImage bi = new BufferedImage(xsize, ysize,
                                         BufferedImage.TYPE_BYTE_GRAY);

    int[] bandMasks = new int[1];  //  ???

    SinglePixelPackedSampleModel sm = new SinglePixelPackedSampleModel(
        DataBuffer.TYPE_BYTE,xsize,ysize,bandMasks);

? - what do I set bandMasks to, or is there an easier way?


    WritableRaster wr = Raster.createWritableRaster(sm, db,new Point());

    bi.setData(wr);

    Appearance appear = new Appearance();

    Texture2D texture = new Texture2D(Texture.BASE_LEVEL,
                        Texture.INTENSITY,
                        image.getWidth(), image.getHeight());

? should I use INTENSITY here?


    ImageComponent2D ic = new ImageComponent2D(
                 ImageComponent.FORMAT_CHANNEL8,image);

? should I use FORMAT_CHANNEL8 here?

    texture.setImage(0, ic);
    texture.setEnable(true);
    texture.setMagFilter(Texture.NICEST);

    appear.setTexture(texture);

    TransparencyAttributes transparencyAttributes =
            new TransparencyAttributes();
    transparencyAttributes.setTransparency(TransparencyAttributes.NONE);
    appear.setTransparencyAttributes(transparencyAttributes);

    BranchGroup grp = new BranchGroup();
    grp.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);

    QuadArray plane = new QuadArray(4,
       GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2 );

    Enumeration e = v.elements();
    // loop over rectangle coordinates to set the plane
    while (e.hasMoreElements()) {
      Object o = e.nextElement();
      Struct3DDouble val = (Struct3DDouble) o;
      Point3f p = new Point3f((float)val.x_value, (float)val.y_value,
                              (float)val.z_value);
      plane.setCoordinate(0, p);
    }

    Point2f q = new Point2f( 1.0f,  1.0f);
    plane.setTextureCoordinate(0, q);
    q.set(1.0f, 0.0f);
    plane.setTextureCoordinate(1, q);
    q.set(0.0f, 0.0f);
    plane.setTextureCoordinate(2, q);
    q.set(0.0f, 1.0f);
    plane.setTextureCoordinate(3, q);

? is there a better way of doing this?  my rectangle will
  eventually be moving...

    Shape3D shape = new Shape3D(plane,appear);
    grp.addChild(shape);

    // add to my root
    myroot.addChild(grp);

Later I would like to try having the texture map transparent.
How would I go about doing this?

Thanks for any help,

Sandy

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