Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  LibGDX - placing two bitmap fonts onto one texture  (Read 3602 times)
0 Members and 1 Guest are viewing this topic.
Offline epicpunnum

Junior Newbie

Exp: 2 years

A man with a plan.

« Posted 2013-08-26 04:57:06 »

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:

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 (, 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:
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.

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?

Currently designing a puzzle-horror game called SLEEP in my free time.
I also draw and animate stuff on Youtube. Cheesy
Offline davedes
« Reply #1 - Posted 2013-08-26 12:57:51 »

I have an app for that! Tongue

Or you could just pack the two fonts into an atlas with PixmapPacker, TexturePacker2, or TexturePacker-GUI.

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.

Pages: [1]
  ignore  |  Print  

EgonOlsen (76 views)
2018-06-10 19:43:48

EgonOlsen (56 views)
2018-06-10 19:43:44

EgonOlsen (76 views)
2018-06-10 19:43:20

DesertCoockie (256 views)
2018-05-13 18:23:11

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (157 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!