Thank you to Alessandro and Florin who helped me with the last topic .... :o)

 

 

Actually I have redefined my application so the textures are of type RGBA so I can use the Alpha channel to make the pixels I want invisible, I do this because it has to be dynamic in runtime ... but now I realize that the changes are not been updated ... the code to access the texture is as follows (right now I am testing to create half of the texture transparent)

 

/**********************************************/

            for (int x=0; x<w; x++)

            {

                for (int y=0; y<h; y++)

                {

                    if (x > w/2)

                    {

                        bf.setRGB(x,y,0x0000FF00);

                    } else

                    {

                        bf.setRGB(x,y,0xFF00FF00);

                    }

                }

            }

 

/***********************************************/

where bf is a BufferedImage which I created with:

/***********************************************/

 

bfBufferedImage=new BufferedImage(TEXTURE_SIZE,

                        TEXTURE_SIZE,

                        BufferedImage.TYPE_INT_ARGB);

 

/***************************************************/

which I "attach" to texture and material in the following code:

/***************************************************/

 

Appearance materialAppear=new Appearance();

materialAppear.setCapability(Appearance.ALLOW_TEXTURE_READ);

materialAppear.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

materialAppear.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);

materialAppear.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);

 

ImageComponent2D image=new ImageComponent2D(ImageComponent.FORMAT_RGBA,bfBufferedImage);

 

texture = new Texture2D(Texture2D.BASE_LEVEL,Texture2D.RGBA,TEXTURE_SIZE,TEXTURE_SIZE);

texture.setCapability(Texture2D.ALLOW_IMAGE_READ);

texture.setCapability(Texture2D.ALLOW_IMAGE_WRITE);

texture.setCapability(Texture2D.RGBA);

texture.setImage(0, image);

materialAppear.setTexture(texture);

 

/****************************************************************/

And in runtime I update it with (after changing the RGBA values):

/****************************************************************/

 

ImageComponent2D image=new ImageComponent2D(ImageComponent.FORMAT_RGBA, bfBufferedImage);

texture=(Texture2D)( voAppearance.getTexture());

texture.setImage(0, image);

voAppearance.setTexture(texture);

 

/*****************************************/

 

Could someone please tell me if there is something missing in my code so I can actually make some pixels transparent? ... Because so far, all the texture is completely opaque and it should be half transparent and half opaque.

 

Thank you in advance! :o)

 

Risto.

Reply via email to