APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.graphics.g2d

public Class DistanceFieldFont

extends BitmapFont
Class Inheritance
Imports
com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.graphics.Texture.TextureFilter, com.badlogic.gdx.graphics.glutils.ShaderProgram, com.badlogic.gdx.utils.Array

Renders bitmap fonts using distance field textures, see the Distance Field Fonts wiki article for usage. Initialize the SpriteBatch with the createDistanceFieldShader() shader.

Attention: The batch is flushed before and after each string is rendered.

Author
Florian Falkner

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
DistanceFieldFont.DistanceFieldFontCache

Provides a font cache that uses distance field shader for rendering fonts.

Field Summary

Modifier and TypeField and Description
private float
Inherited from com.badlogic.gdx.graphics.g2d.BitmapFont:
dataintegerregions

Constructor Summary

AccessConstructor and Description
public
DistanceFieldFont(BitmapFont.BitmapFontData data, Array<TextureRegion> pageRegions, boolean integer)

public
public
DistanceFieldFont(FileHandle fontFile, boolean flip)

public
DistanceFieldFont(FileHandle fontFile, FileHandle imageFile, boolean flip, boolean integer)

public
DistanceFieldFont(FileHandle fontFile, FileHandle imageFile, boolean flip)

public
DistanceFieldFont(FileHandle fontFile, TextureRegion region, boolean flip)

public
public

Method Summary

Modifier and TypeMethod and Description
public static ShaderProgram
createDistanceFieldShader()

Returns a new instance of the distance field shader, see https://libgdx.com/wiki/graphics/2d/fonts/distance-field-fonts if the u_smoothing uniform > 0.0.

public float
getDistanceFieldSmoothing()

Returns: The distance field smoothing factor for this font.

protected void
public BitmapFontCache
newFontCache()

Overrides com.badlogic.gdx.graphics.g2d.BitmapFont.newFontCache.

Creates a new BitmapFontCache for this font.

public void
setDistanceFieldSmoothing(float
Set the distance field smoothing factor for this font. SpriteBatch needs to have this shader set for rendering distance field fonts.
distanceFieldSmoothing
)

Inherited from com.badlogic.gdx.graphics.g2d.BitmapFont:
disposedrawdrawdrawdrawdrawgetAscentgetCachegetCapHeightgetColorgetDatagetDescentgetLineHeightgetRegiongetRegiongetRegionsgetScaleXgetScaleYgetSpaceXadvancegetXHeightindexOfisFlippedownsTexturesetColorsetColorsetFixedWidthGlyphssetOwnsTexturesetUseIntegerPositionstoStringusesIntegerPositions

Field Detail

distanceFieldSmoothingback to summary
private float distanceFieldSmoothing

Constructor Detail

DistanceFieldFontback to summary
public DistanceFieldFont(BitmapFont.BitmapFontData data, Array<TextureRegion> pageRegions, boolean integer)
DistanceFieldFontback to summary
public DistanceFieldFont(BitmapFont.BitmapFontData data, TextureRegion region, boolean integer)
DistanceFieldFontback to summary
public DistanceFieldFont(FileHandle fontFile, boolean flip)
DistanceFieldFontback to summary
public DistanceFieldFont(FileHandle fontFile, FileHandle imageFile, boolean flip, boolean integer)
DistanceFieldFontback to summary
public DistanceFieldFont(FileHandle fontFile, FileHandle imageFile, boolean flip)
DistanceFieldFontback to summary
public DistanceFieldFont(FileHandle fontFile, TextureRegion region, boolean flip)
DistanceFieldFontback to summary
public DistanceFieldFont(FileHandle fontFile, TextureRegion region)
DistanceFieldFontback to summary
public DistanceFieldFont(FileHandle fontFile)

Method Detail

createDistanceFieldShaderback to summary
public static ShaderProgram createDistanceFieldShader()

Returns a new instance of the distance field shader, see https://libgdx.com/wiki/graphics/2d/fonts/distance-field-fonts if the u_smoothing uniform > 0.0. Otherwise the same code as the default SpriteBatch shader is used.

getDistanceFieldSmoothingback to summary
public float getDistanceFieldSmoothing()
Returns:float

The distance field smoothing factor for this font.

loadback to summary
protected void load(BitmapFont.BitmapFontData data)

Overrides com.badlogic.gdx.graphics.g2d.BitmapFont.load.

newFontCacheback to summary
public BitmapFontCache newFontCache()

Overrides com.badlogic.gdx.graphics.g2d.BitmapFont.newFontCache.

Doc from com.badlogic.gdx.graphics.g2d.BitmapFont.newFontCache.

Creates a new BitmapFontCache for this font. Using this method allows the font to provide the BitmapFontCache implementation to customize rendering.

Note this method is called by the BitmapFont constructors. If a subclass overrides this method, it will be called before the subclass constructors.

Annotations
@Override
setDistanceFieldSmoothingback to summary
public void setDistanceFieldSmoothing(float distanceFieldSmoothing)
Parameters
distanceFieldSmoothing:float

Set the distance field smoothing factor for this font. SpriteBatch needs to have this shader set for rendering distance field fonts.

com.badlogic.gdx.graphics.g2d back to summary

private Class DistanceFieldFont.DistanceFieldFontCache

extends BitmapFontCache
Class Inheritance

Provides a font cache that uses distance field shader for rendering fonts. Attention: breaks batching because uniform is needed for smoothing factor, so a flush is performed before and after every font rendering.
Author
Florian Falkner

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
draw(Batch spriteBatch, int start, int end)

Overrides com.badlogic.gdx.graphics.g2d.BitmapFontCache.draw.

private float
private void
setSmoothingUniform(Batch spriteBatch, float smoothing)

Inherited from com.badlogic.gdx.graphics.g2d.BitmapFontCache:
addTextaddTextaddTextaddTextaddTextcleardrawgetColorgetFontgetLayoutsgetPageCountgetVertexCountgetVerticesgetVerticesgetXgetYsetAlphassetColorsetColorsetColorssetColorssetColorssetColorssetColorssetPositionsetTextsetTextsetTextsetTextsetTextsetUseIntegerPositionstinttranslateusesIntegerPositions

Constructor Detail

DistanceFieldFontCacheback to summary
public DistanceFieldFontCache(DistanceFieldFont font)
DistanceFieldFontCacheback to summary
public DistanceFieldFontCache(DistanceFieldFont font, boolean integer)

Method Detail

drawback to summary
public void draw(Batch spriteBatch)

Overrides com.badlogic.gdx.graphics.g2d.BitmapFontCache.draw.

Annotations
@Override
drawback to summary
public void draw(Batch spriteBatch, int start, int end)

Overrides com.badlogic.gdx.graphics.g2d.BitmapFontCache.draw.

Annotations
@Override
getSmoothingFactorback to summary
private float getSmoothingFactor()
setSmoothingUniformback to summary
private void setSmoothingUniform(Batch spriteBatch, float smoothing)