Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Raizor on September 30, 2012

Title: Fonts in 64k intros
Post by: Raizor on September 30, 2012
I was wondering if anyone had any thoughts or suggestions for handling fonts in 64k intros?

The normal approaches seem to be either a 1 bit bitmap font (black & white) or using existing system fonts (TTF such as Arial etc). Both of these methods seem quite limited to me, so I'm wondering if there are alternatives. I guess the SDF font stuff Hellfire posted about a little while ago would be excluded on size grounds as it needs a fairly large PNG to represent distance fields. My only other thought would be to write something to process existing vector based fonts and somehow recreate these in code using a minimal number of points and some curves (bezier or whatever). I can see this last technique being quite difficult to implement, so I wonder if anyone else has an other insights?

Cheers,

raizor
Title: Re: Fonts in 64k intros
Post by: Blacksheep8Bit on September 30, 2012
Well, if you are planning to make some oldskool demo, i would recomend converting the font bitmap in an byte array so you don't have to deal with headers, you should make a code generator if you don't want to spend time converting from binary to hex.


the 'a' letter is stored in each bit of 8 bytes, so we have 8x8 bits in the end

00011100 = 0x1C
00100010 = 0x22
01000001 = 0x41
01111111 = 0x7F
01000001 = 0x41
01000001 = 0x41
01000001 = 0x41
00000000 = 0x00



byte letters[32][8] = { { 0x1c,0x22,0x41,0x7F,0x41,0x41,0x41,0x00 }, // a
{ ... }, // b
{ ... }, ... };



Or again like you said, you can use windows fonts with opengl, but they tend to be slow, VERY slow if you want great detail... And vector fonts aren't easy to make, specially if you want something that looks great.

I Still prefer the oldskool fonts btw, since thats the kind of demo i like to make.
Title: Re: Fonts in 64k intros
Post by: hellfire on September 30, 2012
Quote from: Raizor on September 30, 2012I was wondering if anyone had any thoughts or suggestions for handling fonts in 64k intros?
I guess the SDF font stuff Hellfire posted about a little while ago would be excluded on size grounds
There's already a version of the tool which creates a vectorized outline of the character data.
Drop me a note if that's of any use for you.
Title: Re: Fonts in 64k intros
Post by: Raizor on September 30, 2012
@Blacksheep8Bit, thanks. I'm trying to avoid any bitmaps at all at the moment if possible, so I think some kind of vectorized font is the way to go. Not sure how small I'll be able to get things, will keep you posted :)

@Hellfire, note dropped :)
Title: Re: Fonts in 64k intros
Post by: mrmudlord on October 14, 2012
In my craptro, I use a custom font which loads from memory.

The handle given to CreateFont is like this:
QuoteHANDLE m_fonthandle = AddFontMemResourceEx(
         fontdata,          // font resource
         fontdata_len,          // number of bytes in font resource
         NULL,             // Reserved. Must be 0.
         &nFonts         // number of fonts installed
         );
where  *fontdata is a pointer and fontdata_len is the length in bytes of the resource. Then on end you do RemoveFontMemResourceEx().

In my most recent prod I am working on for a demoparty, I just use a bitmap for the raster font.
Title: Re: Fonts in 64k intros
Post by: Raizor on October 14, 2012
Quote from: mrmudlord on October 14, 2012
In my craptro, I use a custom font which loads from memory.

The handle given to CreateFont is like this:
QuoteHANDLE m_fonthandle = AddFontMemResourceEx(
         fontdata,          // font resource
         fontdata_len,          // number of bytes in font resource
         NULL,             // Reserved. Must be 0.
         &nFonts         // number of fonts installed
         );
where  *fontdata is a pointer and fontdata_len is the length in bytes of the resource. Then on end you do RemoveFontMemResourceEx().

In my most recent prod I am working on for a demoparty, I just use a bitmap for the raster font.

I assume this is a bitmap font Mudlord? I'm aiming more for vector based fonts that are nice and small. Looks like extracting and optimising font outlines from TTF is the way to go at the moment. Still haven't had time to look into it properly yet, but will post my findings here when I do. Thanks.
Title: Re: Fonts in 64k intros
Post by: mrmudlord on October 14, 2012
Sadly thats the case, its a bitmap font. D:
I am also looking for the same thing you are looking for (ways to do decent font rendering/kerning).
Title: Re: Fonts in 64k intros
Post by: Blacksheep8Bit on October 14, 2012
This:
http://nehe.gamedev.net/tutorial/outline_fonts/15004/
(wglUseFontOutlines)

But i guess this is what you mentioned with the "using existing system fonts (TTF such as Arial etc).", i only didn't understood why do you think this is limited...
Title: Re: Fonts in 64k intros
Post by: Raizor on October 14, 2012
Quote from: Blacksheep8Bit on October 14, 2012
This:
http://nehe.gamedev.net/tutorial/outline_fonts/15004/
(wglUseFontOutlines)

But i guess this is what you mentioned with the "using existing system fonts (TTF such as Arial etc).", i only didn't understood why do you think this is limited...

That requires that the font is already installed on the target machine, so you're pretty limited in what fonts you can use (arial, helvetica etc). If you wanted to use a font that's not included in a standard Windows install, you'd need to carry it with you exe, which is gonna eat up a lot of space (and likely bump the intro size over 64k).
Title: Re: Fonts in 64k intros
Post by: Raizor on October 14, 2012
Quote from: mrmudlord on October 14, 2012
Sadly thats the case, its a bitmap font. D:
I am also looking for the same thing you are looking for (ways to do decent font rendering/kerning).

If you're not worried about size, this is worth checking out: BMFont (http://www.angelcode.com/products/bmfont/).
Title: Re: Fonts in 64k intros
Post by: mrmudlord on October 15, 2012
Quote from: Raizor on October 14, 2012
Quote from: Blacksheep8Bit on October 14, 2012
This:
http://nehe.gamedev.net/tutorial/outline_fonts/15004/
(wglUseFontOutlines)

But i guess this is what you mentioned with the "using existing system fonts (TTF such as Arial etc).", i only didn't understood why do you think this is limited...

That requires that the font is already installed on the target machine, so you're pretty limited in what fonts you can use (arial, helvetica etc). If you wanted to use a font that's not included in a standard Windows install, you'd need to carry it with you exe, which is gonna eat up a lot of space (and likely bump the intro size over 64k).

Unless you use the code I posted, yes, thats true. My lines just allows you to pick other fonts not installed on the end users system, thus removing that problem. Doesn't matter if they are outline or not, as long as they are TTF, they should be fine. I even tried *.FON files with degrees of success. Though depending on the font type, quality can vary. :/
Title: Re: Fonts in 64k intros
Post by: Faun on December 09, 2012
Quote from: Raizor on September 30, 2012
I was wondering if anyone had any thoughts or suggestions for handling fonts in 64k intros?

The normal approaches seem to be either a 1 bit bitmap font (black & white) or using existing system fonts (TTF such as Arial etc). Both of these methods seem quite limited to me, so I'm wondering if there are alternatives. I guess the SDF font stuff Hellfire posted about a little while ago would be excluded on size grounds as it needs a fairly large PNG to represent distance fields. My only other thought would be to write something to process existing vector based fonts and somehow recreate these in code using a minimal number of points and some curves (bezier or whatever). I can see this last technique being quite difficult to implement, so I wonder if anyone else has an other insights?

Cheers,

raizor

I used Efgen to generate fonts to binary, that way you can embed it into your intro. It does not add much to the size and is the most nifty thing I have done to this day. Just follow the tutorial on the Efgen site and feel free to see how I did in my source for "Fauntastic!".