Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTF font rendering #17

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open

TTF font rendering #17

wants to merge 26 commits into from

Conversation

haekb
Copy link
Owner

@haekb haekb commented Jan 13, 2020

(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
Copy link
Owner Author

haekb commented Jan 14, 2020

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
Copy link
Owner Author

haekb commented Jan 15, 2020

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
Copy link
Owner Author

haekb commented Jan 16, 2020

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.

This was crashing, but I think I've fixed it..
@haekb
Copy link
Owner Author

haekb commented Jan 16, 2020

Added flushing folders on resolution change.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant