question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Quality of Text and bitmapText

See original GitHub issue

Expected Behavior

Text and BitmapText should be visually equal to a Sprite with the same text and same styles.

Current Behavior

The bitmapText and Text are not equal, and not equal to an Sprite with the same text and style.

  • Black: The image from photoshop with the same default settings found in PIXI.TextStyle ( except font size, see the settings bellow)
  • Red : BitmapText using bitmapFont
  • White: Text

image

image

Steps to Reproduce

https://jsfiddle.net/Bouh/avogx4n1/2/

Environment

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
daraboscommented, Oct 12, 2021

I hit this issue and came up with an awful solution. I extract the font texture to a buffer, clip the values, and put it back in the BitmapFont.

Before After
before after
// Make the font.
const f = PIXI.BitmapFont.from('RulerGold', { ... });
// Get the pixels.
const t1 = f.pageTextures[0];
const rt = app.renderer.generateTexture(new PIXI.Sprite(t1));
let data = app.renderer.plugins.extract.pixels(rt);
// Apply thresholds. 200 for colors, 100 for alpha.
data = data.map((x, i) => x < (i % 4 === 3 ? 100 : 200) ? 0 : 255);
// Put the result back into the font.
const t2 = PIXI.BaseTexture.fromBuffer(data, t1.width, t1.height);
f.pageTextures[0].baseTexture = t2;
for (const k in f.chars) {
  f.chars[k].texture.baseTexture = t2;
}

If you have a PIXI.settings.RESOLUTION > 1, set it to 1 before this snippet and back to your resolution after.

1reaction
bigtimebuddycommented, Sep 17, 2020

That example is complicated, let’s simplify it more without Pixi: https://jsfiddle.net/bigtimebuddy/sc8pgL07/

Inherently, rendering text on canvas without antialias & fillText is not possible (unless someone figured this out). If you need a pixel-looking font, you should probably use a bitmap-font generation tool (e.g. bmGlyph) which probably has more options or there are some approaches where you scale render it at a large size and scale down.

Related: https://www.html5gamedevs.com/topic/23136-how-to-disable-font-antialiasing/

The best I could do it by picking the right sizes plus nearest scaleMode. But it’s not perfect. https://jsfiddle.net/bigtimebuddy/wmkxsgcq/

Screen Shot 2020-09-17 at 10 18 12 AM

Read more comments on GitHub >

github_iconTop Results From Across the Web

Quality of Text and bitmapText · Issue #6884 · pixijs ... - GitHub
Text and BitmapText should be visually equal to a Sprite with the same text and same styles. Current Behavior. The bitmapText and Text...
Read more >
new PIXI.BitmapText (text, style) - PixiJS
Advantages can include sharper image quality (like text) and faster rendering on canvas. The main disadvantage is movement of objects may appear less...
Read more >
PIXI.BitmapText
A BitmapText object will create a line or multiple lines of text using bitmap font. ... Advantages can include sharper image quality (like...
Read more >
Text vs BitmapText ( performance ), the conclusion ? - Phaser 2
BitmapText is really just a spritesheet. Text is rasterizing font glyphs on a canvas. And in WebGL there's the extra step of uploading...
Read more >
Bitmap Text object - GDevelop wiki
A Bitmap Text displays a text using a “Bitmap Font” (an image ... Note that the rendering quality can be affected, because the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found