Skip to content

Commit

Permalink
gdx-ttf fonts bleed black color onto glyphs when they have shadows of…
Browse files Browse the repository at this point in the history
… any color (#7391)

* Add default transparent color to shadow pixmap

* Improved performance by eliminating unecessary fill

* Update FreeTypeFontGenerator.java

* Added missing import

* Updated changelog

* Fixed format violation

* Update CHANGES
  • Loading branch information
WinterAlexander committed Apr 27, 2024
1 parent f2f176f commit 748ae62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Android: Add configuration option to render under the cutout if available on the device.
- Fix: Keep SelectBox popup from extending past right edge of stage.
- Added Framebuffer multisample support (see GL31FrameBufferMultisampleTest.java for basic usage)
- Fix: Fonts generated with gdx-freetype no longer bleed when drawn with a shadow

[1.12.1]
- LWJGL3 Improvement: Audio device is automatically switched if it was changed in the operating system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData;
import com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph;
import com.badlogic.gdx.graphics.g2d.Gdx2DPixmap;
import com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun;
import com.badlogic.gdx.graphics.g2d.PixmapPacker;
import com.badlogic.gdx.graphics.g2d.PixmapPacker.GuillotineStrategy;
Expand Down Expand Up @@ -527,7 +528,11 @@ public FreeTypeBitmapFontData generateData (FreeTypeFontParameter parameter, Fre
int mainW = mainPixmap.getWidth(), mainH = mainPixmap.getHeight();
int shadowOffsetX = Math.max(parameter.shadowOffsetX, 0), shadowOffsetY = Math.max(parameter.shadowOffsetY, 0);
int shadowW = mainW + Math.abs(parameter.shadowOffsetX), shadowH = mainH + Math.abs(parameter.shadowOffsetY);
Pixmap shadowPixmap = new Pixmap(shadowW, shadowH, mainPixmap.getFormat());
// use the Gdx2DPixmap constructor to avoid filling the pixmap twice
Pixmap shadowPixmap = new Pixmap(
new Gdx2DPixmap(shadowW, shadowH, Pixmap.Format.toGdx2DPixmapFormat(mainPixmap.getFormat())));
shadowPixmap.setColor(packer.getTransparentColor());
shadowPixmap.fill();

Color shadowColor = parameter.shadowColor;
float a = shadowColor.a;
Expand Down

0 comments on commit 748ae62

Please sign in to comment.