Search in sources :

Example 26 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class FreeTypeDisposeTest method render.

public void render() {
    if (Gdx.input.justTouched()) {
        for (int i = 0; i < 10; i++) {
            if (font != null) {
                font.dispose();
            }
            FileHandle fontFile = Gdx.files.internal("data/arial.ttf");
            FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
            FreeTypeFontParameter parameter = new FreeTypeFontParameter();
            parameter.size = 15;
            font = generator.generateFont(parameter);
            generator.dispose();
        }
        for (int i = 0; i < 10; i++) System.gc();
        Gdx.app.log("FreeTypeDisposeTest", "generated 10 fonts");
        Gdx.app.log("FreeTypeDisposeTest", Gdx.app.getJavaHeap() + ", " + Gdx.app.getNativeHeap());
    }
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 27 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class FreeTypeTest method create.

@Override
public void create() {
    boolean flip = false;
    batch = new SpriteBatch();
    if (flip) {
        OrthographicCamera cam = new OrthographicCamera();
        cam.setToOrtho(flip);
        cam.update();
        batch.setProjectionMatrix(cam.combined);
    }
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), flip);
    FileHandle fontFile = Gdx.files.internal("data/arial.ttf");
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(fontFile);
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 15;
    parameter.flip = flip;
    parameter.genMipMaps = true;
    // parameter.shadowOffsetX = 1;
    // parameter.shadowOffsetY = 1;
    // parameter.shadowColor = Color.GREEN;
    // parameter.borderWidth = 1f;
    // parameter.borderColor = Color.PURPLE;
    FreeTypeBitmapFontData fontData = generator.generateData(parameter);
    ftFont = generator.generateFont(parameter);
    generator.dispose();
}
Also used : FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) FreeTypeFontParameter(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter) FileHandle(com.badlogic.gdx.files.FileHandle) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) FreeTypeBitmapFontData(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeBitmapFontData) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 28 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class ShaderCollectionTest method setEnvironment.

public void setEnvironment(String name) {
    if (name == null)
        return;
    if (cubemap != null) {
        cubemap.dispose();
        cubemap = null;
    }
    if (name.equals("<none>")) {
        if (environment.has(CubemapAttribute.EnvironmentMap)) {
            environment.remove(CubemapAttribute.EnvironmentMap);
            shaderProvider.clear();
        }
    } else {
        FileHandle root = Gdx.files.internal("data/g3d/environment");
        FacedCubemapData faces = new FacedCubemapData(root.child(name + "_PX.png"), root.child(name + "_NX.png"), root.child(name + "_PY.png"), root.child(name + "_NY.png"), root.child(name + "_PZ.png"), root.child(name + "_NZ.png"), // FIXME mipmapping on desktop
        false);
        cubemap = new Cubemap(faces);
        faces.load(CubemapSide.NegativeX, root.child(name + "_NX.png"));
        cubemap.load(faces);
        if (!environment.has(CubemapAttribute.EnvironmentMap))
            shaderProvider.clear();
        environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap));
    }
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) CubemapAttribute(com.badlogic.gdx.graphics.g3d.attributes.CubemapAttribute) FacedCubemapData(com.badlogic.gdx.graphics.glutils.FacedCubemapData) Cubemap(com.badlogic.gdx.graphics.Cubemap)

Example 29 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class GwtBinaryTest method create.

@Override
public void create() {
    FileHandle handle = Gdx.files.internal("data/arial.ttf");
    bytes = new byte[(int) handle.length()];
    DataInputStream in = new DataInputStream(handle.read());
    for (int i = 0; i < 100; i++) {
        try {
            bytes[i] = in.readByte();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 30 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class AssetsFileGenerator method main.

public static void main(String[] args) {
    FileHandle file = new FileHandle(args[0]);
    StringBuffer list = new StringBuffer();
    args[0] = args[0].replace("\\", "/");
    if (!args[0].endsWith("/"))
        args[0] = args[0] + "/";
    traverse(file, args[0], list);
    new FileHandle(args[0] + "/assets.txt").writeString(list.toString(), false);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)79 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)23 IOException (java.io.IOException)22 Array (com.badlogic.gdx.utils.Array)18 File (java.io.File)18 Element (com.badlogic.gdx.utils.XmlReader.Element)9 Texture (com.badlogic.gdx.graphics.Texture)8 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 IntArray (com.badlogic.gdx.utils.IntArray)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)5 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)4 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)4 Json (com.badlogic.gdx.utils.Json)4 GwtFileHandle (com.badlogic.gdx.backends.gwt.GwtFileHandle)3 Color (com.badlogic.gdx.graphics.Color)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 Writer (java.io.Writer)3