Search in sources :

Example 46 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class FreeTypePackTest method render.

@Override
public void render() {
    Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    float x = 10;
    float y = Gdx.graphics.getHeight() - 10;
    int renderCalls = 0;
    // inside the Enum in order to reduce allocations in the render loop.
    for (FontStyle style : FontStyle.values()) {
        for (FontSize size : FontSize.values()) {
            BitmapFont fnt = getFont(style, size);
            fnt.draw(batch, style.name() + " " + size.size + "pt: The quick brown fox jumps over the lazy dog", x, y);
            y -= fnt.getLineHeight() + 10;
        }
        y -= 20;
    }
    BitmapFont font = getFont(FontStyle.Regular, FontSize.Medium);
    font.draw(batch, text, 10, font.getCapHeight() + 10);
    // draw all glyphs in background
    batch.setColor(1f, 1f, 1f, 0.15f);
    batch.draw(regions.first(), 0, 0);
    batch.setColor(1f, 1f, 1f, 1f);
    batch.end();
}
Also used : BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 47 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont 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 48 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.

the class GwtTest method create.

@Override
public void create() {
    Preferences pref = Gdx.app.getPreferences("test");
    boolean resultb = pref.getBoolean("test");
    int resulti = pref.getInteger("test");
    shader = new ShaderProgram(Gdx.files.internal("data/shaders/shader-vs.glsl"), Gdx.files.internal("data/shaders/shader-fs.glsl"));
    if (!shader.isCompiled())
        throw new GdxRuntimeException(shader.getLog());
    mesh = new Mesh(VertexDataType.VertexBufferObject, true, 6, 0, VertexAttribute.Position(), VertexAttribute.TexCoords(0));
    mesh.setVertices(new float[] { -0.5f, -0.5f, 0, 0, 1, 0.5f, -0.5f, 0, 1, 1, 0.5f, 0.5f, 0, 1, 0, 0.5f, 0.5f, 0, 1, 0, -0.5f, 0.5f, 0, 0, 0, -0.5f, -0.5f, 0, 0, 1 });
    texture = new Texture(new Pixmap(Gdx.files.internal("data/badlogic.jpg")), true);
    texture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    String params = Gdx.files.internal("data/gwttestparams.txt").readString();
    numSprites = Integer.parseInt(params);
    batch = new SpriteBatch();
    positions = new ArrayList<Vector2>();
    for (int i = 0; i < numSprites; i++) {
        positions.add(new Vector2(MathUtils.random() * Gdx.graphics.getWidth(), MathUtils.random() * Gdx.graphics.getHeight()));
    }
    sprite = new Sprite(texture);
    sprite.setSize(64, 64);
    sprite.setOrigin(32, 32);
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    cache = font.newFontCache();
    cache.setColor(Color.RED);
    cache.setText("This is a Test", 0, 0);
    atlas = new TextureAtlas(Gdx.files.internal("data/pack"));
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) Mesh(com.badlogic.gdx.graphics.Mesh) Texture(com.badlogic.gdx.graphics.Texture) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) Vector2(com.badlogic.gdx.math.Vector2) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) Preferences(com.badlogic.gdx.Preferences) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 49 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project commons-gdx by gemserk.

the class FontResourceBuilder method build.

@Override
public BitmapFont build() {
    BitmapFont bitmapFont;
    if (imageFile != null && fontFile != null) {
        Texture texture = new Texture(imageFile);
        texture.setFilter(minFilter, magFilter);
        bitmapFont = new BitmapFont(fontFile, new Sprite(texture), false);
    } else if (textureAtlasId != null && regionId != null) {
        if (fontFile == null)
            throw new IllegalArgumentException("Can't build a font resource without specifying the fontFile.");
        TextureAtlas atlas = resourceManager.getResourceValue(textureAtlasId);
        AtlasRegion region = atlas.findRegion(regionId);
        if (region == null)
            throw new IllegalArgumentException("Can't build a font resource, region " + regionId + " not found in texture atlas");
        bitmapFont = new BitmapFont(fontFile, region, false);
    } else {
        // if image file and font file are not specified, it creates a new default bitmap font.
        bitmapFont = new BitmapFont();
        bitmapFont.getRegion().getTexture().setFilter(minFilter, magFilter);
    }
    bitmapFont.setUseIntegerPositions(useIntegerPositions);
    if (fixedWidthGlyphs != null)
        bitmapFont.setFixedWidthGlyphs(fixedWidthGlyphs);
    for (int i = 0; i < spacings.size(); i++) {
        FontSpacing fontSpacing = spacings.get(i);
        CharSequence charSequence = fontSpacing.charSequence;
        BitmapFontUtils.spacing(bitmapFont, charSequence, fontSpacing.spacing);
    }
    bitmapFont.setScale(scale);
    return bitmapFont;
}
Also used : Sprite(com.badlogic.gdx.graphics.g2d.Sprite) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) Texture(com.badlogic.gdx.graphics.Texture)

Example 50 with BitmapFont

use of com.badlogic.gdx.graphics.g2d.BitmapFont in project Entitas-Java by Rubentxu.

the class PongState method initialize.

@Override
public void initialize() {
    // Input
    Camera camera = engine.getManager(BaseSceneManager.class).getDefaultCamera();
    Batch batch = engine.getManager(BaseSceneManager.class).getBatch();
    BitmapFont font = engine.getManager(BaseGUIManager.class).getDefaultFont();
    context.core.createEntity().addBall(false).addView(new Circle(0, 0, 8)).addMotion(MathUtils.clamp(1, 230, 300), 300);
    context.core.createEntity().addPlayer(Player.ID.PLAYER1).addScore("Player 1: ", 180, 470).addView(new Rectangle(-350, 0, Pong.PLAYER_WIDTH, Pong.PLAYER_HEIGHT)).addMotion(0, 0);
    context.core.createEntity().addPlayer(Player.ID.PLAYER2).addScore("Player 2: ", 480, 470).addView(new Rectangle(350, 0, Pong.PLAYER_WIDTH, Pong.PLAYER_HEIGHT)).addMotion(0, 0);
    systems.add(new InputSystem(context.core)).add(new ContactSystem(context.core)).add(new BoundsSystem(context.core)).add(new MoveSystem(context.core)).add(new RendererSystem(context.core, engine.sr, camera, batch, font));
}
Also used : Circle(com.badlogic.gdx.math.Circle) Batch(com.badlogic.gdx.graphics.g2d.Batch) BaseSceneManager(com.ilargia.games.entitas.egdx.base.managers.BaseSceneManager) Rectangle(com.badlogic.gdx.math.Rectangle) BaseGUIManager(com.ilargia.games.entitas.egdx.base.managers.BaseGUIManager) Camera(com.badlogic.gdx.graphics.Camera) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Aggregations

BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)104 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)64 Texture (com.badlogic.gdx.graphics.Texture)31 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)21 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)18 Stage (com.badlogic.gdx.scenes.scene2d.Stage)16 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)13 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)12 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)11 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)10 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)10 AssetManager (com.badlogic.gdx.assets.AssetManager)9 Color (com.badlogic.gdx.graphics.Color)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 InputAdapter (com.badlogic.gdx.InputAdapter)7 Actor (com.badlogic.gdx.scenes.scene2d.Actor)7 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)7 FileHandle (com.badlogic.gdx.files.FileHandle)6 Pixmap (com.badlogic.gdx.graphics.Pixmap)6 GlyphLayout (com.badlogic.gdx.graphics.g2d.GlyphLayout)6