Fading out Text?

I have been trying to get this to work for a while and can't seem to make it happen.  Can someone give me a simple example of how to fade out Text in jME?  I know how to fade out a Quad, but when I apply an alphastate to my Text it chops off the right half of the letters and still doesn't even fade.



Help would be greatly appreciated. :wink:

Regular Text, or the 3d stuff?

Regular 2D Text.

Have you tried using the alpha value of the text color?  Text already has an alpha state.

Yes, I tried creating a ColorRGBA and setDefaultColor and setTextColor and the alpha adjustments never apply.  It works fine with the same ColorRGBA on a Quad though.

Text is not rendered as vertices so the color does not apply, I think. Have a look into the Text rendering method of LWJGLRenderer (using special GL method, iirc).

Hmmm, okay, well so how do I make it fade-out then?

to my knowledge, nothing can render without vertices :wink:



but the vertex, color setup etc are done internally in the lwjglfont class that is used by lwjglrenderer when rendering text…it sets the colors to the text color though so it should be fine to set the alpha of the text with Text.setTextColor to the fade value…

Try it yourself…it no worky.  :stuck_out_tongue:

MrCoder said:

to my knowledge, nothing can render without vertices ;)

I don't think so - or does glDrawPixels use vertices :?
But you might be right that Text is not drawn to the frame buffer but textures some vertices (I did never have a look at that).

that's very correct! forget my stupid post! but Text is not drawn that way no…

Good info…so is there any way to make it render alpha?  It would seem this is a bug in Text then since it should take care of the alpha on ColorRGBA itself since it is being custom renderered…right?

irrisor said:

Text is not rendered as vertices so the color does not apply, I think. Have a look into the Text rendering method of LWJGLRenderer (using special GL method, iirc).


In LWJGLRenderer.draw(Text):

    public void draw(Text t) {
        if (font == null) {
            font = new LWJGLFont();
        }
        [b]font.setColor(t.getTextColor());[/b]
        applyStates(t.states);
        font.print(this, (int) t.getWorldTranslation().x, (int) t
                .getWorldTranslation().y, t.getWorldScale(), t.getText(), 0);
    }



And In LWJGLFont.print(...):

GL11.glColor4f(fontColor.r, fontColor.g, fontColor.b, fontColor.a);

Also… Simply going into any simple game demo and typing:


fps.setTextColor(new ColorRGBA(1,1,1,.25f));



Shows that alpha fading works and is pretty easy.  Play with that last float value to prove it to yourself.

Argh!  :-o



Although you are correct, my problem is still a valid one.  I have been setting a ColorRGBA via setTextColor and then modifying that color.a instead of setting it each time.  I was looking at setTextColor and instead of keeping that ColorRGBA to be used internally when rendering, it just keeps four floats internally instead.  This is why it is happening is because it's not keeping the reference.  I'll change my code for now, but it would be best if this were fixed to work like other objects in the scenegraph that keep the DefaultColor instead of just taking the curren values and then dropping it.



Thanks for the info though Renanse, you put your finger right on the real problem.

Hey, a piece of code that already respects encapsulation! And you want to change it to the worse? :-o

I would rather suggest to update the javadoc instead.

probably representing it internally as a colorrgba would be better than the four floats, then you could at least do a getTextColor().a = …

irrisor said:

Hey, a piece of code that already respects encapsulation! And you want to change it to the worse? :-o
I would rather suggest to update the javadoc instead.


At this point it's less about what's respectful and more about what's consistant I'd argue.

disclaimer: I'm one of those user that heavily uses that fact jME "does not respect encapsulation" :P

I would agree with Llama there.  It would be one thing if all of jME did the same thing, but the reason this issue even came up was that I had a method that I knew worked on Quads, but when I tried the same approach on Text it didn't work.  Inconsistency is a killer in an API.  Particularly in a case like this that without the wonder that is Renanse I would probably still be trying to figure out why alpha was broken.  :stuck_out_tongue:

you could still do something like text.getTextColor().a = newValue;