Giter Club home page Giter Club logo

gdx-freetype-gwt's Introduction

gdx-freetype-gwt

You ever wanted to use freetype on the web version of your game but couldn't? Now you can!

Versions

You have to use a matching libGDX and gdx-freetype-gwt version. See this table for compatibility.

libGDX gdx-freetype-gwt Note
1.9.11-SNAPSHOT 1.9.11-SNAPSHOT
1.9.10 1.9.10.1 Fixes #9
1.9.10 1.9.10 Don't use. Use 1.9.10.1 instead

How-To

  1. Go to your GdxDefinition.gwt.xml in your html subproject

Add

<inherits name="com.badlogic.gdx.graphics.g2d.freetype.freetype-gwt" />

after

<inherits name='com.badlogic.gdx.backends.gdx_backends_gwt' />

  1. Change your build.gradle of the html subproject

Add

 implementation "com.github.intrigus.gdx-freetype-gwt:gdx-freetype-gwt:$version"
 implementation "com.github.intrigus.gdx-freetype-gwt:gdx-freetype-gwt:$version:sources"
  1. Modify your HtmlLauncher.java (or if it's not named so, modify the class in your html project that extends GwtApplication)

Add

@Override
public void onModuleLoad () {
	FreetypeInjector.inject(new OnCompletion() {
		public void run () {
			// Replace HtmlLauncher with the class name
			// If your class is called FooBar.java than the line should be FooBar.super.onModuleLoad();
			HtmlLauncher.super.onModuleLoad();
		}
	});
}
  1. Profit and Enjoy

Note

If gradle fails to resolve the dependency this most likely means that there no matching gdx-freetype-gwt version has been published.

You should try previous versions since freetype is generally updated rarely.

In any case open an issue.

gdx-freetype-gwt's People

Contributors

frosty-j avatar intrigus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gdx-freetype-gwt's Issues

pls fix bug Mac OS iphone can not be used

Because I don't know how to grab the mac os or Apple phone logs, but once I comment out the font-related code, I can run normally.
Online project urgent, ask for help

freetype.js loads infinity

I included this lib like your instructions in the readme.
You can see in the screenshot, that freetype.js loads infinity.
CollapseTheGame - Google Chrome 06 12 2019 22_14_12

I'm using libgdx version 1.9.11-SNAPSHOT. I load my ttf via the asset manager like here described in the wiki. If you want, I can invite you to the project

Crash and glitch on GWT export

I got a weird bug and I'm not sure if this problem is on my side or in this library.
Everytime I set the FreeTypeFontParameter "shadowOffsetX" and "shadowOffsetY" I get following exception:
com.google.gwt.core.client.JavaScriptException: (TypeError) : P.cX is not a function

I don't know how to fix that because everything i tried is not working ... I can use every parameter except these two.

EDIT:
I found the source of the failure. File: FreeTypeFontGenerator Line: 538
He fails to cast the pixmap correctly

UPDATE:
i just changed the casting an get weird looking effects:
unbenannt

Exception: Cannot enlarge memory arrays, if the font file size > 10M

Hi, Thanks for your work for this project. I use it on my web game, It's just works fine before.
When I use a new ttf file on my game, I got an error:

Error: java.lang.RuntimeException: com.google.gwt.core.client.JavaScriptException: (String) : abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value 16777216, (2) compile with -s ALLOW_MEMORY_GROWTH=1 which adjusts the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ") at jsStackTrace@http://localhost:8080/dist/html/freetype.js:1:19835 stackTrace@http://localhost:8080/dist/html/freetype.js:1:20018 abort@http://localhost:8080/dist/html/freetype.js:24:10812 abortOnCannotGrowMemory@http://localhost:8080/dist/html/freetype.js:1:20872 enlargeMemory@http://localhost:8080/dist/html/freetype.js:1:21317 dynamicAlloc@http://localhost:8080/dist/html/freetype.js:1:6848 _sbrk@http://localhost:8080/dist/html/freetype.js:1:346073 Kp@http://localhost:8080/dist/html/freetype.js:7:105374 _w@http://localhost:8080/dist/:145:30 Xw@http://localhost:8080/dist/:130:68 ux@http://localhost:8080/dist/:9:396 L_e@http://localhost:8080/dist/:5:20 DXe@http://localhost:8080/dist/:150:93 td@http://localhost:8080/dist/:49:318 yd@http://localhost:8080/dist/:156:60 gh@http://localhost:8080/dist/:69:216 Bg@http://localhost:8080/dist/:1:21888 mg/<@http://localhost:8080/dist/:155:53 If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.

After some research, I find the font file size > 10M(almost/around this value) will cause this problem.
Do you have any idea on this? or this is a limit of javascrip side?
Thank you.

Here is ttf file for test (only, I copied from windows fonts folder).
Deng.zip

Release an official extension for gdx

I'll have to look into, whether it's possible to install this extension without modifying the gdx source.
Besides that, everything should be pretty straightforward.

Not working?

Followed the directions provided, but getting this error:

GwtApplication: exception: (InvalidStateError) : An attempt was made to use an object that is not, or is no longer, usable

This is the code that is causing the error. (When I revert this back to regular Bitmapfont instead of Freetype, the error goes away. So the error it definitely has to do with Freetype.

package com.game.client.fonts;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;

/**
 * @author Nelson
 * Manages all game fonts
 */

public class GameFont {


    private FreeTypeFontGenerator generator;
    private BitmapFont font;


    /**
     * Game Fonts constructor
     *
     * @param fontFile the file location for the font file
     * @param size     the size of the font
     */

    public GameFont(String fontFile, int size) {
        generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/font.ttf"));
        FreeTypeFontParameter parameter = new FreeTypeFontParameter();
        parameter.size = 24;
        font = generator.generateFont(parameter);
        font.setColor(Color.YELLOW);
    }

    public BitmapFont getFont() {
        return font;
    }

    public FreeTypeFontGenerator getGenerator() {
        return generator;
    }

    public void setFont(BitmapFont font) {
        this.font = font;
    }

    public void dispose() {
        getFont().dispose();
        getGenerator().dispose();
    }

}

InvalidStateError when using a font containing CJK characters.

Gdx-freetype-gwt works fine if using western fonts.
However, it may throw InvalidStateError when using fonts containing CJK characters like DroidSansFallback.ttf or KaiGenGothicTW-Normal.ttf.

On Microsoft Edge, it works fine.

On Chrome, it displays "Uncaught Error: java.lang.RuntimeException: com.google.gwt.core.client.JavaScriptException: (InvalidStateError) : Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0."

On Firefox, it shows "Error: java.lang.RuntimeException: com.google.gwt.core.client.JavaScriptException: (InvalidStateError) : An attempt was made to use an object that is not, or is no longer, usable".

Font with shadows crashes

When I set shadow parameters in FreeTypeFontParameter the app crashes.

Here is a sample code:

    private void createFonts() {
        FreeTypeFontGenerator.setMaxTextureSize(1024);

        FreeTypeFontGenerator fontGenerator = mAssetManager.get(mTextFontDesc);
        FreeTypeFontGenerator.FreeTypeFontParameter fontParameter;
        BitmapFont font;

        fontParameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
        fontParameter.size = 64;
        //fontParameter.shadowColor = Color.BLACK;
        //fontParameter.shadowOffsetX = 6;
        //fontParameter.shadowOffsetY = 6;
        fontParameter.genMipMaps = true;
        fontParameter.minFilter = Texture.TextureFilter.MipMapLinearNearest;
        fontParameter.magFilter = Texture.TextureFilter.MipMapLinearNearest;

        font = fontGenerator.generateFont(fontParameter);
        font.setUseIntegerPositions(true);

        mMainTitleFontStyle = new Label.LabelStyle(font, new Color(0xf9f901ff));
    }

If I uncomment any of shadow parameter GWT application crashes with the following error:
Error: java.lang.RuntimeException: java.lang.ClassCastException.

I'm really confused about that.. what could be the cause?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.