Commit graph

103 commits

Author SHA1 Message Date
Clownacy
af837edda4 Remove an unneeded font variable 2020-11-05 19:42:04 +00:00
Clownacy
9e9b8942a5 Don't upload glyphs with no width or height
The SDLTexture renderer gives annoying errors otherwise
2020-11-03 13:33:32 +00:00
Clownacy
4a6b04d306 Fix a typo 2020-11-03 12:03:59 +00:00
Clownacy
744ddcaacf Fix use of uninitialised memory in Font.cpp
This can cause random text corruption
2020-10-25 23:37:58 +00:00
Clownacy
98f78716f7 Update portable branch with licence boilerplates
Also added Cameron Cawley to the licence
2020-10-23 19:18:13 +01:00
Clownacy
a14aa30bde Avoid a const violation 2020-10-21 00:00:35 +01:00
Clownacy
8a560eb873 Shut up a GCC warning 2020-10-18 14:25:44 +01:00
Clownacy
7ab6866d6b Change Font.cpp to use CP1252 instead of UTF-8
This is accurate to the original EXE, which would default to CP1252
depending on what region Windows was set to. This is the case for
English and Spanish regions, and likely others.

This should make this branch compatible with a number of fan-made
translations. However, this also makes it so that the `PutText`
functions will no longer support UTF-8 strings.

Modders may prefer to switch to UTF-8 entirely, so I've left the old
UTF-8 parsing function in a comment.
2020-10-03 12:29:43 +01:00
Clownacy
f2c0f94e42 Faster binary search 2020-09-18 02:55:45 +01:00
Clownacy
729565b5ca Might as well not obscure the code 2020-09-18 02:05:37 +01:00
Clownacy
b0974c3def Binary-search optimisations and fixes 2020-09-18 02:03:14 +01:00
Clownacy
4e936d4f45 Add a todo 2020-09-17 20:13:44 +01:00
Clownacy
f61ffac785 Turns out raw unicode *is* UTF32 2020-09-17 19:43:12 +01:00
Clownacy
ada7d91f17 Tiny cleanup 2020-09-17 19:39:34 +01:00
Clownacy
79586f5b90 Speed-up glyph lookup 2020-09-17 19:34:18 +01:00
Clownacy
ff44d2fd06 Note something 2020-09-17 18:42:36 +01:00
Clownacy
2b848ad16e Finally, Windows-accurate font sizing
And of course Windows has some weird bug that has to be emulated with
FreeType.
2020-09-17 15:02:42 +01:00
Clownacy
c9f17c4411 Rename FreeType font functions 2020-09-17 15:02:42 +01:00
Clownacy
9973dddbbd Restore the FreeType code
Now you can select either the FreeType fonts or the pre-rendered
fonts with CMake's 'FREETYPE_FONTS' option.
2020-09-17 15:02:42 +01:00
Clownacy
a542a5c11d Cleanup and fixes 2020-09-17 15:02:42 +01:00
Clownacy
fe76fe6dea Big scary messy unfinished font overhaul
This is currently hardcoded to 640x480 English builds.

What I've done is temporarily gutted the FreeType2 font renderer, and
instead introduced a system where the font is read from a
pre-rendered font atlas. This allows me to get 100% accurate font
rendering to Windows XP... because I literally created these atlases
with Windows XP.

So not only does this eliminate the issue of FreeType producing
misshapen glyphs, but it also works around the copyright issue
regarding bundling the Courier New and MS Gothic fonts with CSE2.

You see, font files can be copyrighted like any old software, however
typefaces have a lot less protection - they're basically fair-game.
IANAL, of course - look it up yourself.

I don't really want to throw away the FreeType font system since I
spent a ton of time working on it, it allows you to use other font
files, and I'll probably wind up needing it for CSE2EX. I guess I'll
just have to find some way to either have the two systems coexist, or
make it so one or the other can be selected at compile-time.
2020-09-17 15:02:36 +01:00
Clownacy
febeb1b692 More-efficient way of determining atlas size 2020-09-16 18:18:37 +01:00
Clownacy
c6af61de5e Chars aren't guaranteed to overflow at 256 2020-09-15 20:49:24 +01:00
Clownacy
11bbad7372 Cleanup
Now RenderBackend_DrawGlyph doesn't pass an unnecessary parameter
2020-09-15 19:40:10 +01:00
Clownacy
746ebb822c Bump glyph cache limit to 256
This should fit an entire extended ASCII set, and also help Japanese
support a little by having a larger pool of cached glyphs.
2020-09-14 15:29:04 +01:00
Clownacy
63e4ac9aa9 Remove RenderBackend_FlushGlyphs
No longer used for anything
2020-09-14 12:25:39 +01:00
Clownacy
daa55b1a3c Allow font atlases to be non-square
Saves a little memory in some cases. It's the backend's job to decide
if this is a problem or not, and pad it if it has to.
2020-09-14 12:08:27 +01:00
Clownacy
17da39fa14 Rename FontObject to Font
Explicitly calling it an object just seems unnecessarily verbose,
2020-09-14 11:54:37 +01:00
Clownacy
1625d3961d Correct some awkward wording 2020-09-14 11:50:48 +01:00
Clownacy
bf93334b94 Fix out-of-bounds font atlas accesses 2020-09-13 12:30:01 +01:00
Clownacy
5e7f514b6f Hopefully fix font atlas pixel bleeding 2020-09-13 12:29:50 +01:00
Clownacy
84c1e00c95 Tidy-up some code 2020-09-10 19:07:46 +01:00
Clownacy
69f3fbcd5a Change a dumb parameter 2020-09-10 17:56:22 +01:00
Clownacy
988f1128dd Convert a bunch of ints to size_t
ints are dumb - only use them when you have to
2020-09-10 17:36:21 +01:00
Clownacy
0a912b7f11 Change some type from int to size_t 2020-09-08 04:36:45 +01:00
Clownacy
d1a9754784 Fix uninitialised memory usage 2020-09-08 03:23:36 +01:00
Clownacy
fcf1e9d0c4 Link glyph array from back to front
This way, glyphs are allocated from front to bacl, which makes the
atlas much more pleasant to look at.
2020-09-08 03:14:53 +01:00
Clownacy
80df145d3f Fix Japanese text
Sweet mercy I'm bad at FreeType2
2020-09-08 03:04:01 +01:00
Clownacy
1d9446d425 Update SDLSurface renderer for new font batcher 2020-09-07 23:44:51 +01:00
Clownacy
096fa3b578 New custom font batcher
Previously, the font batching system was very shoddy: basically,
glyph bitmaps would be cached to system memory, and uploaded
on-demand to the GPU.

The OpenGL3, OpenGLES2, and SDLTexture backends relied on
`cute_spritebatch.h` to handle batching. While nice, this library is
overkill: it's intended for managing a whole game, not just a couple
of glyphs. It also depends on C++11, which is something I'd rather be
without.

Being so complex, it appears that internally it spams the backend
when merging atlases together. According to bug reports, this causes
the game to skip a lot of frames.

Instead, I've ditched the system-memory-side caching, and made the
game maintain its own atlas. Unlike `cute_spritebatch.h`, this one
doesn't purge glyphs after they've gone unused for 30(?) seconds -
instead, glyphs are only purged when room in the atlas runs out, at
which point the oldest glyph is replaced. This method doesn't involve
creating or destroying atlases at runtime, avoiding the overhead of
whatever OpenGL/DirectX do internally when that happens.

Currently only the OpenGL3, OpenGLES2, and Software renderers have
been updated with this - the others will fail to build.

I know immediate-mode renderers won't benefit from this, but it
replaces the leaky old caching system, so it's still an improvement.
2020-09-07 23:11:01 +01:00
Clownacy
1dcf3333fc Simplify some font logic 2020-09-06 20:30:47 +01:00
Clownacy
f4ffee2c99 Remove redundant font flag 2020-09-06 20:30:39 +01:00
Clownacy
34d3b8e664 Improve font rendering
This change fixes uneven glyph heights
2020-09-06 20:30:30 +01:00
Clownacy
df42d9300f Disable font anti-aliasing by default
CSE2 Portable is meant to be a purist thing - experiencing Cave Story
the way it was meant to be. The crappy font rendering was definitely
not how it was meant to be.
2020-09-06 17:10:46 +01:00
Gabriel Ravier
32c8795ead src: Cleaned up includes to only (and always) include what we use
Signed-off-by: Gabriel Ravier <gabravier@gmail.com>
2020-07-01 18:26:22 +02:00
Clownacy
770f3be74e Make font sizes more accurate to the vanilla EXE
This is such a nightmare
2020-06-30 16:04:25 +01:00
Clownacy
63dd995343 Make 320x240 monochrome fonts not look terrible
Turns out, for all this time, I never enabled FreeType's
mono-hinting.

Now, the English font looks pretty good. I can't say the same for the
Japanese one though - that one looks identical. I guess Noto doesn't
come with hinting data? FreeType's auto-hinter just makes it look
worse...
2020-06-27 23:13:09 +01:00
Clownacy
88602ccaf6 Do not create glyph textures with no height/width
This should fix the issue with cute_spritebatch.h, described in #116.
2020-04-29 13:09:51 +01:00
Clownacy
231d1b93a7 Add error-handling to Font.cpp
Prevents a crash on the Wii U port in 1280x720 when you try to open
the pause menu. There's a giant delay now instead, and I'm not sure
where it comes from. Still, it's an improvement.
2020-04-23 20:50:12 +01:00
Clownacy
4d322be866 Change render backend namespace to RenderBackend_ 2020-04-04 20:24:34 +01:00