Text class doesn't work with all colors: my solution

I've seen Text element doesn't work correctly:

Print some text in black color on white background will hide the text with defaut created text object :|.



After search, it's because the blend function isn't appropriate: Currently they add the text color to destination pixel. All text on white background doesn't display anything…



Here the problem:



//in  Text.java
 /*
    * @return an alpha states for allowing 'black' to be transparent
    */
    private static AlphaState getFontAlpha() {
        AlphaState as1 = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
        as1.setBlendEnabled( true );
        as1.setSrcFunction( AlphaState.SB_SRC_ALPHA );
        as1.setDstFunction( AlphaState.DB_ONE );
        return as1;
    }




I've modified the code like this:


   /*
    * @return an alpha states for allowing 'black' to be transparent
    */
    private static AlphaState getFontAlpha() {
        AlphaState as1 = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
        as1.setBlendEnabled( true );
        as1.setSrcFunction( AlphaState.SB_SRC_ALPHA );
        as1.setDstFunction( AlphaState.DB_ONE_MINUS_SRC_ALPHA );
        return as1;
    }



and created a new fontboard in 32bits RGBA PNG, the same older but with transparency channel (I can send this if someone want...).

    public static final String DEFAULT_FONT = "com/jme/app/defaultfont.png";



So now, all it's ok.

In search I think have find a forget here (AlphaState.java):


    public void setSrcFunction(int srcFunction) {
        if(srcFunction < 0 || srcFunction > 6) {
            srcFunction = SB_SRC_ALPHA;
        }
        srcBlend = srcFunction;
        setNeedsRefresh(true);
    }



Don't they must write:

    public void setSrcFunction(int srcFunction) {
        if(srcFunction < 0 || srcFunction > 8) {
            srcFunction = SB_SRC_ALPHA;
        }
        srcBlend = srcFunction;
        setNeedsRefresh(true);
    }



??? Because on before we have:


    public final static int SB_ZERO = 0;
    ...

    public final static int SB_ONE_MINUS_DST_ALPHA = 7;
   
    public final static int SB_SRC_ALPHA_SATURATE = 8;

nice that you found those. :slight_smile:

thank you very much anykeyh! That was exactly the solution to a problem I had. btw. the bug: well found!



weeeeee!



dhdd

Just saw this for the first time.  Thanks for posting the fixes. I've locally applied them and added a nicer font texture with the proper alpha channel.