MZ Pixel Fonts Are Blurred in Centered Text in Menus, Can I Fix This?

I found a pixelated font for my low-resolution game, but the problem is, on certain menus (title screen, options, etc.) the text is blurred on certain lines. I think it's because they way RMMZ centers text causes it to land on half-pixels. I've tried getting the pixels to align properly by writing a plugin and using math.Round(), but nothing seems to work. Does anyone have any idea which variables I should try tweaking or if there's a different method I should try, or is it just another hard-coded "quirk" of RPG Maker that I'm just going to have to work around?

Screenshot 2024-11-02 032536.png
Here's an image of what's going on in case visual aid is necessary. Note how "New Game" and "Continue" are nice and crisp while "Options" is blurred a little.
Judging by my notes, I've used this to fix a similar problem in my project:
JavaScript:
/*:
 * @target MZ
 * @plugindesc Render at integer coordinates.
 * @url https://forums.rpgmakerweb.com/threads/172982/
 */
PIXI.settings.ROUND_PIXELS = true;
Judging by my notes, I've used this to fix a similar problem in my project:
JavaScript:
/*:
 * @target MZ
 * @plugindesc Render at integer coordinates.
 * @url https://forums.rpgmakerweb.com/threads/172982/
 */
PIXI.settings.ROUND_PIXELS = true;
This doesn't seem to work for me.

Closest I've gotten to a solution is nudging the x-coordinate for where the text renders half a pixel to the side. This unblurs the previously affected text, but the rest of the text is blurred.

I also forgot to mention that since I'm making a low-resolution game, I scaled down the text boxes by about half to fit. Do you think that affected it in any way? I might have, as RPG Maker, quite ironically, is weirdly hostile to low-res games.
The above should work, but this was a small oversight i the rpg_core.js/rmmz_core.js, and can easily be fixed with the below code as a plugin ^^

Both solutions are valid, @caethyril's solution is ESPECIALLY good to use if you intend to keep all your games assets from blurring( i.e. characters, windows, pictures, if for some reason they use a float value.., etc ).

JavaScript:
Bitmap.prototype.drawText = function(text, x, y, maxWidth, lineHeight, align) {
    // [Note] Different browser makes different rendering with
    //   textBaseline == 'top'. So we use 'alphabetic' here.
    const context = this.context;
    const alpha = context.globalAlpha;
    maxWidth = maxWidth || 0xffffffff;
    let tx = x;
    let ty = Math.round(y + lineHeight / 2 + this.fontSize * 0.35);
    if (align === "center") {
//===================================================================//
// The line below is how it CURRENTLY is done...
//===================================================================//
        // tx += maxWidth / 2;
//===================================================================//
// THIS is what it should be to prevent blurring in certain circumstances.
//===================================================================//
        tx += Math.round( maxWidth / 2 );
    }
    if (align === "right") {
        tx += maxWidth;
    }
    context.save();
    context.font = this._makeFontNameText();
    context.textAlign = align;
    context.textBaseline = "alphabetic";
    context.globalAlpha = 1;
    this._drawTextOutline(text, tx, ty, maxWidth);
    context.globalAlpha = alpha;
    this._drawTextBody(text, tx, ty, maxWidth);
    context.restore();
    this._baseTexture.update();
};
Still doesn't work. "Options" is still blurry.

Like, I've said, Math.round() doesn't seem to be working for getting the text aligned for some reason. I don't know what to do.
😴 Drat. From what I've gathered, font rendering seems to be a fairly intractable source of anti-aliasing, at least in web development. There are workarounds, though!

Scaling down the text's texture may well cause blurriness; by default a window's contents is set to linear scaling ("smooth") rather than nearest-neighbour. If you want to remove all graphical anti-aliasing, you could try a plugin like this:
For the font stuff specifically, maybe check out one of these:
  • Eli Bitmap Font - bitmap fonts are probably best if you want total graphical fidelity.
  • OpenType Pixel Font Renderer by utunnels - custom TrueType parser, see this post for MZ:
  • Sharp Text by MechPen - this one seems to manually "fix" font edges on a per-pixel basis?
😴 Drat. From what I've gathered, font rendering seems to be a fairly intractable source of anti-aliasing, at least in web development. There are workarounds, though!

Scaling down the text's texture may well cause blurriness; by default a window's contents is set to linear scaling ("smooth") rather than nearest-neighbour. If you want to remove all graphical anti-aliasing, you could try a plugin like this:
For the font stuff specifically, maybe check out one of these:
  • Eli Bitmap Font - bitmap fonts are probably best if you want total graphical fidelity.
  • OpenType Pixel Font Renderer by utunnels - custom TrueType parser, see this post for MZ:
  • Sharp Text by MechPen - this one seems to manually "fix" font edges on a per-pixel basis?
:LZSexcite: Caethryl, OpenType Pixel Font Renderer is the exact plugin I have been looking for and you have saved my life by showing it to me. This is a MILLION times better than trying to get the pixels to align manually!

​

I'm glad that you find it useful.
To be fair, every method requires the font itself to be accurate. My plugin also do Math.round but on every corner of the glyphs. I also found certain characters became deformed while other characters from the same font looked OK.
If that happens, you'll need to find a good font or use fontforge to fix those characters.

Original thread: https://forums.rpgmakerweb.com/threads/pixel-fonts-are-blurred-in-centered-text-in-menus-can-i-fix-this.172982/