use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class BitmapFontMetricsTest method create.
@Override
public void create() {
spriteBatch = new SpriteBatch();
atlas = new TextureAtlas("data/pack");
smallFont = new BitmapFont();
font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), atlas.findRegion("verdana39"), false);
font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false);
renderer = new ShapeRenderer();
renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class BitmapFontTest method render.
@Override
public void render() {
// red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1;
int viewHeight = Gdx.graphics.getHeight();
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Test wrapping or truncation with the font directly.
if (!true) {
// BitmapFont font = label.getStyle().font;
BitmapFont font = this.font;
font.getRegion().getTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
font.getData().setScale(2f);
renderer.begin(ShapeRenderer.ShapeType.Line);
renderer.setColor(0, 1, 0, 1);
float w = Gdx.input.getX();
// w = 855;
renderer.rect(10, 10, w, 500);
renderer.end();
spriteBatch.begin();
String text = "your new";
text = "How quickly [RED]daft jumping zebras vex.";
// text = "Another font wrap is-sue, this time with multiple whitespace characters.";
text = "test with AGWlWi AGWlWi issue";
if (true) {
// Test wrap.
layout.setText(font, text, 0, text.length(), font.getColor(), w, Align.center, true, null);
} else {
// Test truncation.
layout.setText(font, text, 0, text.length(), font.getColor(), w, Align.center, false, "...");
}
float meowy = (500 / 2 + layout.height / 2 + 5);
font.draw(spriteBatch, layout, 10, 10 + meowy);
spriteBatch.end();
renderer.begin(ShapeRenderer.ShapeType.Line);
renderer.setColor(0, 1, 0, 1);
for (int i = 0, n = layout.runs.size; i < n; i++) {
GlyphRun r = layout.runs.get(i);
renderer.rect(10 + r.x, 10 + meowy + r.y, r.width, -font.getLineHeight());
}
renderer.end();
font.getData().setScale(1f);
return;
}
// Test wrapping with label.
if (false) {
label.debug();
label.getStyle().font = font;
label.setStyle(label.getStyle());
label.setText("How quickly [RED]daft[] jumping zebras vex.");
label.setWrap(true);
// label.setEllipsis(true);
label.setAlignment(Align.center, Align.right);
label.setWidth(Gdx.input.getX() - label.getX());
label.setHeight(label.getPrefHeight());
} else {
// Test various font features.
spriteBatch.begin();
String text = "Sphinx of black quartz, judge my vow.";
font.setColor(Color.RED);
float x = 100, y = 20;
float alignmentWidth;
if (false) {
alignmentWidth = 0;
font.draw(spriteBatch, text, x, viewHeight - y, alignmentWidth, Align.right, false);
}
if (true) {
alignmentWidth = 280;
font.draw(spriteBatch, text, x, viewHeight - y, alignmentWidth, Align.right, true);
}
font.draw(spriteBatch, "[", 50, 60, 100, Align.left, true);
font.getData().markupEnabled = true;
font.draw(spriteBatch, "[", 100, 60, 100, Align.left, true);
font.getData().markupEnabled = false;
// 'R' and 'p' are in different pages
String txt2 = "this font uses " + multiPageFont.getRegions().size + " texture pages: RpRpRpRpRpNM";
spriteBatch.renderCalls = 0;
// regular draw function
multiPageFont.setColor(Color.BLUE);
multiPageFont.draw(spriteBatch, txt2, 10, 100);
// expert usage.. drawing with bitmap font cache
BitmapFontCache cache = multiPageFont.getCache();
cache.clear();
cache.setColor(Color.BLACK);
cache.setText(txt2, 10, 50);
cache.setColors(Color.PINK, 3, 6);
cache.setColors(Color.ORANGE, 9, 12);
cache.setColors(Color.GREEN, 16, txt2.length());
cache.draw(spriteBatch, 5, txt2.length() - 5);
cache.clear();
cache.setColor(Color.BLACK);
float textX = 10;
textX += cache.setText("[black] ", textX, 150).width;
multiPageFont.getData().markupEnabled = true;
textX += cache.addText("[[[PINK]pink[]] ", textX, 150).width;
textX += cache.addText("[PERU][[peru] ", textX, 150).width;
cache.setColor(Color.GREEN);
textX += cache.addText("green ", textX, 150).width;
textX += cache.addText("[#A52A2A]br[#A52A2ADF]ow[#A52A2ABF]n f[#A52A2A9F]ad[#A52A2A7F]in[#A52A2A5F]g o[#A52A2A3F]ut ", textX, 150).width;
multiPageFont.getData().markupEnabled = false;
cache.draw(spriteBatch);
// tinting
cache.tint(new Color(1f, 1f, 1f, 0.3f));
cache.translate(0f, 40f);
cache.draw(spriteBatch);
spriteBatch.end();
// System.out.println(spriteBatch.renderCalls);
renderer.begin(ShapeType.Line);
renderer.setColor(Color.BLACK);
renderer.rect(x, viewHeight - y - 200, alignmentWidth, 200);
renderer.end();
}
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class AssetManagerTest method create.
public void create() {
Gdx.app.setLogLevel(Application.LOG_ERROR);
Resolution[] resolutions = { new Resolution(320, 480, ".320480"), new Resolution(480, 800, ".480800"), new Resolution(480, 856, ".480854") };
ResolutionFileResolver resolver = new ResolutionFileResolver(new InternalFileHandleResolver(), resolutions);
manager = new AssetManager();
manager.setLoader(Texture.class, new TextureLoader(resolver));
manager.setErrorListener(this);
load();
Texture.setAssetManager(manager);
batch = new SpriteBatch();
font = new BitmapFont(Gdx.files.internal("data/font.fnt"), false);
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class AssetManagerTest method load.
private void load() {
// Gdx.app.setLogLevel(Logger.DEBUG);
start = TimeUtils.nanoTime();
tex1 = new Texture("data/animation.png");
tex2 = new TextureAtlas(Gdx.files.internal("data/pack"));
font2 = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false);
// tex3 = new Texture("data/test.etc1");
// map = TiledLoader.createMap(Gdx.files.internal("data/tiledmap/tilemap csv.tmx"));
// atlas = new TileAtlas(map, Gdx.files.internal("data/tiledmap/"));
// renderer = new TileMapRenderer(map, atlas, 8, 8);
shader = new ShaderProgram(Gdx.files.internal("data/g2d/batchCommon.vert").readString(), Gdx.files.internal("data/g2d/monochrome.frag").readString());
System.out.println("plain took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
start = TimeUtils.nanoTime();
manager.load("data/animation.png", Texture.class);
// manager.load("data/pack1.png", Texture.class);
manager.load("data/pack", TextureAtlas.class);
// manager.load("data/verdana39.png", Texture.class);
manager.load("data/verdana39.fnt", BitmapFont.class);
// manager.load("data/multipagefont.fnt", BitmapFont.class);
// manager.load("data/test.etc1", Texture.class);
// manager.load("data/tiledmap/tilemap csv.tmx", TileMapRenderer.class, new
// TileMapRendererLoader.TileMapParameter("data/tiledmap/", 8, 8));
manager.load("data/i18n/message2", I18NBundle.class, new I18NBundleLoader.I18NBundleParameter(reloads % 2 == 0 ? Locale.ITALIAN : Locale.ENGLISH));
manager.load("data/g2d/monochrome.frag", ShaderProgram.class, new ShaderProgramLoader.ShaderProgramParameter() {
{
vertexFile = "data/g2d/batchCommon.vert";
}
});
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class AccelerometerTest method create.
@Override
public void create() {
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
batch = new SpriteBatch();
}
Aggregations