Commit graph

91 commits

Author SHA1 Message Date
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
Clownacy
c4aa8e28bb More refactoring 2020-04-01 14:57:07 +01:00
Clownacy
5dbca99e19 Extremely horrible terrible nightmare refactoring
Working on ridding CSE2 of its hard SDL2 dependency.

For now, I have a rudimentary GLFW3 backend.
2020-03-31 21:56:10 +01:00
Clownacy
e3cd7ce353 Add glyph-batching to OpenGL renderer
Unfortunately, sub-pixel font rendering had to go. It wasn't portable
anyway (not every display is an LCD with R->G->B ordering).
2020-02-01 22:37:59 +00:00
Clownacy
eaf2de05b6 Add glyph-batching to the SDLTexture backend
Hope it will be this easy for the OpenGL backend
2020-02-01 17:49:26 +00:00
Clownacy
639039ce3a Added Backend_PrepareToDrawGlyphs
This is to reduce OpenGL context changes, and help pave the way for
glyph-batching
2020-02-01 16:40:23 +00:00
Clownacy
b650294b8b Change LoadFileToMemory's function signature 2020-01-26 20:06:31 +00:00
Clownacy
1fe73f9aab Explicitly compare pointers in Font.cpp to NULL 2020-01-23 01:05:29 +00:00
Clownacy
3c9ff22c22 Add better error-handling to Font.cpp
Co-authored-by: Gabriel Ravier <gabravier@gmail.com>
2019-11-09 14:19:26 +00:00
Clownacy
e4fcf6a5e1 Fixed spacing for fonts that aren't Courier New
Previous, I used a godawful hack to emulate Windows' API, but it
seems this only ever worked for Courier New: with something like
Liberation Mono, it would squash the font. Now I'm just giving up on
it, and using actual font sizes rather than "cell" sizes.

I'm not sure if this is accurate the original EXE.
2019-09-04 19:21:51 +00:00
Clownacy
ae8aeae2ac Restored the new font system 2019-09-04 15:43:28 +00:00
Clownacy
f956eb9264 Mostly ASM-accurate Draw.cpp
See #74
2019-08-31 17:43:45 +01:00
Clownacy
ce8b5651bc Give the FONT_PIXEL_MODE enums a type 2019-08-21 16:25:02 +00:00