Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Asset Manager loader for Distance Field fonts #377

Open
rubybrowncoat opened this issue Sep 24, 2021 · 1 comment
Open
Labels
assets Issues of the ktx-assets module help wanted More advanced tasks that might require advanced knowledge of Kotlin, KTX or LibGDX

Comments

@rubybrowncoat
Copy link

rubybrowncoat commented Sep 24, 2021

A loader for asset manager in the vein of what was done with ktx-freetype but for distance field fonts: https://github.com/libgdx/libgdx/wiki/Distance-field-fonts

A loader for this type of fonts might be desirable, I couldn't figure out how to integrate the loading method specified in the wiki with my asset manager setup.


Alternatively to that, I have used https://github.com/maltaisn/msdf-gdx to load msdf fonts seamlessly like this, because the library includes a loader and I just needed to load it onto the Asset Manager:

val assetManager = AssetManager()
assetManager.setLoader(MsdfFontLoader(InternalFileHandleResolver()))

enum class DistanceFieldFontAssets(val path: String) {
    DankMono32("skin/dank-mono-48-msdf.fnt"),
}

fun AssetManager.load(asset: DistanceFieldFontAssets) = load<MsdfFont>(asset.path)
operator fun AssetManager.get(asset: DistanceFieldFontAssets) = getAsset<MsdfFont>(asset.path)

DistanceFieldFontAssets.values().forEach { assetManager.load(it).finishLoading() }

I'm not sure about all the differences between the distance field fonts described on the libgdx wiki and the ones used by the msdf library, so I can't really say if using that library is sufficient to cover the use cases set forth by the libgdx wiki.

@czyzby czyzby added assets Issues of the ktx-assets module help wanted More advanced tasks that might require advanced knowledge of Kotlin, KTX or LibGDX labels Sep 24, 2021
@czyzby
Copy link
Member

czyzby commented Sep 24, 2021

Seems like the font requires a custom shader, which means we would either have to extend BitmapFont to ensure it is called before rendering, or document this for the users. The examples show how to implement outlines and shadows, so we probably should consider adding these as well. Either way, an extension for msdf-gdx would be cleaner, but the library does not seem to be updated anymore. I might tinker with it in a while, but no promises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assets Issues of the ktx-assets module help wanted More advanced tasks that might require advanced knowledge of Kotlin, KTX or LibGDX
Projects
None yet
Development

No branches or pull requests

2 participants