Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (604)
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 6303 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: 25



« 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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
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,
            g.getFontRenderContext());
      Rectangle2D rect = layout.getBounds();
     
      float cx = (float) rect.getX();
      float cy = boxSize - g.getFontMetrics().getDescent();
     
      dos.writeFloat(cx);
      dos.writeFloat(cy);
      dos.writeFloat((float) rect.getWidth());
      dos.writeFloat((float) rect.getHeight());
   }
   
   dos.close();
   g.dispose();
}

Offline Matthias

Senior Devvie


Medals: 3
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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (136 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!