LibGDX - placing two bitmap fonts onto one texture

Hello world! I’m working on a game and I’ve recently switched to LibGDX to get better performance, more target platforms, and a few other reasons, so I’m relatively new to a lot of OpenGL.
From what I understand, LibGDX runs most efficiently using bitmap fonts rendered to a single texture, that uses a texture atlas to select a specific character. For my purposes, this is fine.

My game uses two fonts - one being a modified version of the other. I have placed them below:


<-Original

<-Modified

While there are cases where I’d use both fonts on their own, there may be times when I need to use both simultaneously. For instance, I will be animating some text to randomly switch to the modified version to provide a “glitchy” aesthetic.

According to this article (http://www.streamingcolour.com/blog/2009/08/27/texture-atlases-and-bitmap-fonts/), the reason bitmap fonts are stored into one texture is because changing to another texture can be a relatively expensive operation.
Here’s the actual quote:

[quote]The reason this is done is that every time OpenGL has to change which texture it’s currently drawing with, it takes time. So if you draw, say, 100 different little sprites every frame, and each one is in it’s own texture, OpenGL has to change which texture it’s using 100 times. This can lead to a lot of inefficiency and can actually significantly slow your rendering code. But if you put those 100 sprites into one big texture atlas, then OpenGL doesn’t need to swap textures, it just changes the coordinates of the current texture each time.
[/quote]
As such, is it possible to put both of my bitmap fonts together as one texture and alternate between the two fonts when necessary? If so, how would I do this in LibGDX?

I have an app for that! :stuck_out_tongue:

Or you could just pack the two fonts into an atlas with PixmapPacker, TexturePacker2, or TexturePacker-GUI.
https://code.google.com/p/libgdx-texturepacker-gui/
https://code.google.com/p/libgdx/wiki/TexturePacker

Then when you create the fonts, you pass to the constructor the font definition for that font and a TextureRegion. Since your glyphs seem to be exactly in the same position, you could probably just generate a single BitmapFontData and share it between both (though there isn’t much of a performance gain). By using texture regions the two BitmapFonts will use the same backing Texture, and be included in the same batch.