Is the alpha channel working?

In a recent post I asked how to fade a Picture…and the advice came back:



// half transparency

myPicture.getMaterial().setColor("m_Color", new ColorRGBA(1, 1, 1, 0.5f));



I believe that this is the correct solution, however, the only attribute from R, G, B, a which affects the Picture are R, G and B.



For awile, I was thinking I had to define a background maybe, but still no results.



Used png and BMP file types, and no luck.



Here is my code:



p = new Picture("Picture");

p.setPosition(0, 0);

p.setWidth(200);

p.setHeight(settings.getHeight());

p.setImage(assetManager, "Interface/Logo/sample.png", false);

renderer.setBackgroundColor(ColorRGBA.Red);

p.getMaterial().setColor("m_Color", new ColorRGBA(1, 1, 1, 0.5f));



Again, moving the a value around, no visual change in image, but the RGB values do respond.



Any help would be appreciated, and thanks in advance.



Bruce C


You need to set useAlpha to true in this call:

p.setImage(assetManager, "Interface/Logo/sample.png", false);


replace false with true

p.setImage(assetManager, "Interface/Logo/sample.png", true);


If you don't want to use an image on the picture you can set alpha blending manually:


p.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

Sure fixes the problem…thanks for the answer.



I think the problem I had was not really understanding the API…so thanks.

Yeah it is a bit complicated at times. Ideally though you would just use a material (j3m) file and load it instead of doing this through code.


Material Transparent Color : Common/MatDefs/Gui/Gui.j3md {
     MaterialParameters {
          m_Color : 1 1 1 0.5
     }
     AdditionalRenderState {
          BlendMode Alpha
     }
}