haekb / nolf1-modernizer

The goal of NOLF Modernizer is to help fix some long standing bugs, and update some more outdated features of the game.
https://haekb.itch.io/nolf-modernizer
45 stars 11 forks source link

TTF font rendering #17

Open haekb opened 4 years ago

haekb commented 4 years ago

(WIP) This PR adds TTF font rendering!..well not really, but kinda!

So while this version of the engine can load TTF fonts, it's limited to system fonts and the actual rendering is incredibly slow.

So what I do to get around this is use a library (SDL TTF) to load custom TTF fonts, format them correctly (the engine expects only a single space in between characters. Which is a huge pain, because fonts like to lie about their glyph width.) export the font sheet to PCX format (the engine only supports PCX for bitmap fonts.) in a encoder I wrote (because there weren't any good small portable ones.) and then immediately load that pcx.

And bam, we have variable size font rendering! 50% of this PR could be avoided if we could create a font from an array of pixels, but we can't.


There's still bug in the glyph rendering. I need to properly take into account the minX and maxX. Right now I'm trimming the start of the character to get the real minX, but some fonts can be cut off on the maxX portion.

Square 721 (included in NOLF2) image

Comic Sans (yay) image

haekb commented 4 years ago

Fixed that bug, and cleaned up a little. It can now load any font that supports all the characters in the character map, which is good enough for me!

If in the future I need to support that, I just need to create a block (or one pixel) character to stand in.

haekb commented 4 years ago

My MakePCX occasionally encodes a "bad" pcx file that only crashes the engine when heap tracking is enabled in gflags. Everything else seems to read it fine.

This occasionally causes the font stuff to crash on several resolution changes. (Or on some cases one!)

Need to figure this out..

haekb commented 4 years ago

Bug fixed. Was off by one in the header...oops. Swapped back to pitch.

Another bug squashed where I wasn't clearing "ThisColumnIsSolid" at the beginning of a Column.

Need to flush all the menus, so they'll run build() on resolution change. Yikes.

haekb commented 4 years ago

Added flushing folders on resolution change.

There's currently a bug where player hud still has some references to the fonts that were destroyed.