Custom Shader on BitmapFont

I’d like my BitmapFont quads to be drawn with a custom material instead of the Common/…/unshaded material.

Do you have any ideas regarding the cleanest way to do this?

I could subclass the BitmapFontLoader and see if I can apply the material to all BitmapFonts (not actually a problem in my case) but I figure you guys will have smarter ideas…?

Really it’s a shame that BitmapFont doesn’t use a j3m file because then it would be easy to override global behavior. However, instead of subclassing, doing loaders, etc., etc. I recommend just having a utility method.

For example, Lemur wanted to fix text to actually be transparent so I added this method to Lemur’s GuiGlobals class:
[java]
public void fixFont( BitmapFont font ) {
for( int i = 0; i < font.getPageSize(); i++ ) {
Material m = font.getPage(i);
m.getAdditionalRenderState().setAlphaTest(true);
m.getAdditionalRenderState().setAlphaFallOff(0.1f);
}
}
[/java]

You could just as easily use something similar to change the material and copy its parameters instead of just setting things on it.

The code is simpler than your approach and it’s easier to rip out if something better comes along someday. Plus, it won’t affect fonts that don’t need it (like the stats fonts).

I am curious what you custom material does, though.

Edit: Note: Lemur is setting alpha test when it should really be setting the alpha discard threshold uniform instead. There were reasons once but they are no longer relevant and I just haven’t fixed it.

Thanks pspeed :slight_smile:

The shader discards pixels that aren’t inside a certain screen coordinate. The idea is that you can have this material on something and it will clip outside of a certain boundary - much like a viewport.

I’m playing around with GLSL mostly, but I’m wondering whether this might be a lightweight way to build a GUI programatically without needing a separate camera or anything each time a parent element ‘clips’ a child element (such as scroll panes).

I believe tonegodGUI does something very similar.