Dark Bit Factory &  Gravity

Dark Bit Factory & Gravity

  • July 30, 2010 *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Pages: [1]   Go Down

Author Topic: Bitmap-Font Maker  (Read 799 times)

0 Members and 1 Guest are viewing this topic.

hellfire

  • Sponsor
  • Pentium
  • *******
  • Karma: 234
  • Offline Offline
  • Posts: 700
    • View Profile
Bitmap-Font Maker
« on: December 22, 2009 »
As a friend of mine asked for a simple way to create bitmaps from true-type-fonts, I dug out an old tool of mine - maybe it's useful for someone else, too.

What it does is rendering each character into a bitmap and tries to place them all into one map.
It creates a list with information about
  x-position
  y-position,
  width,
  height,
  offset from base-column (this is useful for serif-fonts where characters partially overlap),
  offset from base-line
  actual width required by the character (that's where the next character starts)

An extreme example of a single character stored in the map looks like this:


You can specify font, size, bitmap, spacing, number of colours and color-encoding.
There are some additional options like creating a set of required characters from the actual text and exporting image-data as ready to include source-code.

A simple heuristic tries to avoid worst-case scenarios when assembling the different character-bitmaps into a single map - but it's yet far from optimal or even clever.

Download here (3.1mb due to Qt).

Feature requests are welcome.

A very simple example how to use this with OpenGL is attached below.

Have fun.
« Last Edit: December 29, 2009 by hellfire »
Logged

rain_storm

  • Here comes the Rain
  • Senior Member
  • ******
  • Karma: 157
  • Offline Offline
  • Posts: 2871
  • Rain never hurt nobody
    • View Profile
    • WWW
Re: Fontmaker
« Reply #1 on: December 22, 2009 »
Very useful stuff hellfire will definately be making some use of this in future

Pixel_Outlaw

  • Pentium
  • *****
  • Karma: 68
  • Offline Offline
  • Posts: 1206
    • View Profile
Re: Fontmaker
« Reply #2 on: December 22, 2009 »
These kinds of tools always fill a need. Have some karma.
Logged

zawran

  • Sponsor
  • Pentium
  • *******
  • Karma: 54
  • Offline Offline
  • Posts: 778
    • View Profile
    • WWW
Re: Fontmaker
« Reply #3 on: December 22, 2009 »
Looks like a really useful tool, thanks for sharing.
Logged

Voltage

  • Professor
  • Pentium
  • *****
  • Karma: 50
  • Offline Offline
  • Posts: 828
    • View Profile
Re: Fontmaker
« Reply #4 on: December 23, 2009 »
Great tool hellfire.

It has some nice features.... Generate chars list (from sentence), texture size, and the very useful char location array that goes with it.

karma++
Logged

Voltage

  • Professor
  • Pentium
  • *****
  • Karma: 50
  • Offline Offline
  • Posts: 828
    • View Profile
Re: Fontmaker
« Reply #5 on: December 23, 2009 »
I was able to get this working with a simple opengl texture example.

2 things though:

1) The "Save As Array" option in fontmaker doesn't add commas to the end of each line.  I had to manually add these commas.

2) I had a little bit of trouble trying to figure out which OGL settings to use to import this data as a texture.  I used the following:

Code: [Select]
glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, fontdata);
Logged

hellfire

  • Sponsor
  • Pentium
  • *******
  • Karma: 234
  • Offline Offline
  • Posts: 700
    • View Profile
Re: Fontmaker
« Reply #6 on: December 23, 2009 »
I usually use
Code: [Select]
glTexImage2D(
  GL_TEXTURE_2D,
  0,
  GL_ALPHA,
  sizeX,
  sizeY,
  0,
  GL_ALPHA,
  GL_UNSIGNED_BYTE,
  data);
This way all information is inside the alpha-channel so you can use proper blending and specify the color using glcolor.

In your screenshot you need to take the "baseline" parameter into account (the 7th in each row).
Postive value means up, negative value means down.
See screenshot above.
« Last Edit: December 29, 2009 by hellfire »
Logged

Voltage

  • Professor
  • Pentium
  • *****
  • Karma: 50
  • Offline Offline
  • Posts: 828
    • View Profile
Re: Fontmaker
« Reply #7 on: December 23, 2009 »
ah that makes sense.  I did get alpha working, but I did it an ugly way.

I created a temp buffer twice the size of the texture and...

Code: [Select]
for (i=0;i<512*512;i++) {
  buffertmp[i*2]=buffer[i];
  buffertmp[i*2+1]=buffer[i];
}

Then I used GL_RGBA and GL_LUMINANCE_AND_ALPHA (or something similar).

The method shown above(yours) is obviously cleaner.  Thanks for pointing that out.
« Last Edit: December 23, 2009 by Voltage »
Logged

hellfire

  • Sponsor
  • Pentium
  • *******
  • Karma: 234
  • Offline Offline
  • Posts: 700
    • View Profile
Re: Fontmaker
« Reply #8 on: December 23, 2009 »
Well, the goal for the array-export is to keep the data as compact as posibble but still uncompressed (because thats what the exe-packer likes), so I thought it's enough to store a single channel.
If you like to store other formats I could add a selector for that.
I plan to support syntax for different languages, too.
« Last Edit: December 23, 2009 by hellfire »
Logged

combatking0

  • Something something something Dark Side!
  • Senior Member
  • ******
  • Karma: 71
  • Offline Offline
  • Posts: 2543
  • Retroman!
    • View Profile
    • WWW
Re: Fontmaker
« Reply #9 on: December 26, 2009 »
Very nice - finally a feature-rich font editor without ads/fees/viruses. K++
Logged
Coming soon to a screen near you - Retroman, and the Creature from the 3rd Dimension!
Until then, please visit the Pie Movie Database, the Fractigami or the Game Builders' Club pages.

Voltage

  • Professor
  • Pentium
  • *****
  • Karma: 50
  • Offline Offline
  • Posts: 828
    • View Profile
Re: Fontmaker
« Reply #10 on: December 27, 2009 »
ok, I got the alpha channel working as per hellfire's instructions.  And the character positions also.

thanks again hellfire. 

Logged

hellfire

  • Sponsor
  • Pentium
  • *******
  • Karma: 234
  • Offline Offline
  • Posts: 700
    • View Profile
Re: Fontmaker
« Reply #11 on: December 28, 2009 »
The "l" in "reload" isn't properly centered between the "e" and the "o".
So either you didn't take the offset from the base-column into account or I didn't calculate the character-width correctly (haven't tried any font in italics so that's quite possible).
I'll have a look at that later.
Logged

Clyde

  • A Little Fuzzy Wuzzy
  • Contributing Author
  • Senior Member
  • ******
  • Karma: 71
  • Offline Offline
  • Posts: 6965
    • View Profile
Re: Fontmaker
« Reply #12 on: December 28, 2009 »
^^also the m.

Cool, will give this a whirl.
Logged
If only I knew then what I know now.

Voltage

  • Professor
  • Pentium
  • *****
  • Karma: 50
  • Offline Offline
  • Posts: 828
    • View Profile
Re: Fontmaker
« Reply #13 on: December 29, 2009 »
I hadn't included the column adjustments.  I have now.

I'm not using italics, the letters are spinning.  See the attached exe.

The source is a dog's breakfast at the moment.  I'll clean it up a little and post it soon.
Logged

hellfire

  • Sponsor
  • Pentium
  • *******
  • Karma: 234
  • Offline Offline
  • Posts: 700
    • View Profile
Re: Fontmaker
« Reply #14 on: December 29, 2009 »
I'm not using italics, the letters are spinning.  See the attached exe.
Cool :)

Noticed that I didn't reserve enough spare-pixels when rendering fonts with extreme amount of serifs, so I added an option to select it manually - cut regions are marked with a white line.
« Last Edit: December 29, 2009 by hellfire »
Logged

energy

  • Atari ST
  • ***
  • Karma: 14
  • Offline Offline
  • Posts: 183
    • View Profile
    • WWW
Re: Bitmap-Font Maker
« Reply #15 on: December 30, 2009 »
Great tool ,Hellfire....
 :goodpost:
Possible to get output format for MASM???
Logged
Purebasic 4.3, MASM

hellfire

  • Sponsor
  • Pentium
  • *******
  • Karma: 234
  • Offline Offline
  • Posts: 700
    • View Profile
Re: Bitmap-Font Maker
« Reply #16 on: December 30, 2009 »
Sure. I don't use MASM, though. So please post a syntax-example.
Logged

Pages: [1]   Go Up
 

 

B l a c k R a i n V.2 by C r i p

Page created in 0.151 seconds with 18 queries.