JP,

Given two colors as integers and a size (power of two) the following will
give you a Texture object.  Note you can optimize the loops quite a bit but
this should be  a bit clearer.  Standard disclaimer -- this code has *not*
been compiled or tested but has been adapted from working code.

--Mark

   private Texture createTwoByTwoGrid( int color1, int color2, int
widthAndHeight ) {

     // Create the buffered image & color array (integer)
     java.awt.image.BufferedImage bufferedImage = new
java.awt.image.BufferedImage( widthAndHeight, widthAndHeight,
java.awt.image.BufferedImage.TYPE_INT_RGB);
     int [] colorArray = new int[widthAndHeight * widthAndHeight];

     // Cache half of resolution
     int halfResolution = widthAndHeight >> 1;

     for ( int x1 = 0; x1 < halfResolution; x1++ ) {
       int span = x1*widthAndHeight;
       for ( int y1 = 0; y1 < widthAndHeight; y1++ ) {
          if ( y1 < halfResolution )
            colorArray[span + y1] = color1;
          else
            colorArray[span + y1] = color2;
       }
     }

     for ( int x2 = halfResolution; x2 < widthAndHeight; x2++ ) {
       int span = x2*widthAndHeight;
       for ( int y2 = 0; y2 < widthAndHeight; y2++ ) {
          if ( y2 < halfResolution )
            colorArray[span + y2] = color2;
          else
            colorArray[span + y2] = color1;
       }
     }

     bufferedImage .setRGB(0, 0, widthAndHeight, widthAndHeight,
colorArray, 0, widthAndHeight);

     // Create the IC2D with the buffered image
     ImageComponent2D newImage = new
ImageComponent2D(ImageComponent.FORMAT_RGB, bufferedImage );

     // Create texture and set new image
     Texture newTexture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB,
widthAndHeight, widthAndHeight);
     newTexture .setImage(0, newImage);

      // Return gridded image
     return newTexture ;
   }

At 04:23 PM 9/12/2001, you wrote:
>Thank you for the idea Kevin, but will it be that you or does anybody have
>some reference or tutorial of use of BufferedImage and as I join several
>BufferedImages in a texture?


Mark Ferneau                    240-462-6262 (cell)
Director of Adv. Technology             801-437-4608 (efax)
Xtivia Technologies, Inc.               301-279-5703 (home office)
[EMAIL PROTECTED]                      http://www.xtivia.com/
[EMAIL PROTECTED] (wireless email)

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