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();
}
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();
}
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"));
}
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;
}
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));
}
Aggregations