Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
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  
  Fontexturer - make .png images from TTF fonts for OpenGL textures  (Read 12181 times)
0 Members and 1 Guest are viewing this topic.
Offline mlaux

Junior Devvie

Medals: 3

« Posted 2012-03-05 03:54:54 »

I whipped this up for my own use and decided to share it with java-gaming! It allows you to select an installed font on your system and generate a .png image of that font, so you can use it to draw text with OpenGL. There's probably already a tool like this out there. Oh well.

Obligatory screenshot:

Download here.

I'll post the source code if someone requests it.

Offline gimbal

JGO Knight

Medals: 26

« Reply #1 - Posted 2012-03-05 15:29:24 »

Awesome idea. Yes, source code would be appreciated.

Can you imagine I once created a font sheet from a real font... through Photoshop? Sad

BTW: I believe Font has some method with which you can check if a particular character can actually be rendered by that font; using it you can skip all entries that would result in a square. Of course you may have a good reason to leave them in, like having a predictable character location.
Offline mlaux

Junior Devvie

Medals: 3

« Reply #2 - Posted 2012-03-06 01:24:08 »

I kept the nonprintable characters in there so that I could directly look up the coordinates based on the char value without manipulating it (lazy, I know...) but here's the source so people can make any changes they'd like!

Also notably absent is support for bold/italic fonts and there're probably still a few bugs lingering around.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Archibald

Junior Devvie

Projects: 1

« Reply #3 - Posted 2012-03-06 07:30:53 »

Is it for monospace (fixed width) fonts only?
Offline davidllanos22

Junior Devvie

Projects: 2

I'm just a learner!

« Reply #4 - Posted 2012-03-06 12:21:43 »

Wow, thanks! It can be very useful! Now I only have to learn how to use texture fonts in java! I'll try!   Grin

Offline mlaux

Junior Devvie

Medals: 3

« Reply #5 - Posted 2012-03-07 02:48:39 »

Is it for monospace (fixed width) fonts only?

It works with any font. But, it's hard to use it with proportional fonts because it doesn't save the dimension information for the characters.

If anyone's interested, here's a modified PreviewPanel::save method which writes another file called "metrics.ftx" containing the x/y/width/height of the bounding box for all the characters it puts in the .png image.

public void save(File file, String fmt) throws IOException {
   BufferedImage buf = new BufferedImage(sideLength, sideLength, BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = (Graphics2D) buf.getGraphics();
   drawCharacters(g, Color.white);
   ImageIO.write(buf, fmt, file);
   DataOutputStream dos = new DataOutputStream(new FileOutputStream(new File(file.getParent(), "metrics.ftx")));
   for (char ch = MIN_CH; ch <= MAX_CH; ch++) {
      TextLayout layout = new TextLayout(String.valueOf(ch), font,
      Rectangle2D rect = layout.getBounds();
      float cx = (float) rect.getX();
      float cy = boxSize - g.getFontMetrics().getDescent();
      dos.writeFloat((float) rect.getWidth());
      dos.writeFloat((float) rect.getHeight());

Offline Matthias

Senior Devvie

Medals: 5
Projects: 1

TWL - Themable Widget Library

« Reply #6 - Posted 2012-03-09 22:39:05 »

For a more complete font support you can take a look at the BMFont format which also supports kerning.
The TWL Theme Editor has a font generator tool (Tools -> create font) with 3 different rendering methods:
- freetype2: best quality
- AWT drawString
- AWT vector: most effects
Offline mlaux

Junior Devvie

Medals: 3

« Reply #7 - Posted 2012-03-09 23:30:42 »

Well, way to show me up. Tongue

Everyone go use that one now!

Offline ReBirth
« Reply #8 - Posted 2012-03-10 03:41:55 »

I don't like webstart. Will use OP's Grin

Offline _Al3x

Senior Devvie

Medals: 7

Indie Games FTW!

« Reply #9 - Posted 2012-03-10 22:02:19 »

Thanks for sharing Smiley

Pages: [1]
  ignore  |  Print  

Riven (438 views)
2019-09-04 15:33:17

hadezbladez (5290 views)
2018-11-16 13:46:03

hadezbladez (2212 views)
2018-11-16 13:41:33

hadezbladez (5559 views)
2018-11-16 13:35:35

hadezbladez (1156 views)
2018-11-16 13:32:03

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

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

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

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

nelsongames (4739 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 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!