use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class CullTest method create.
@Override
public void create() {
ModelBuilder builder = new ModelBuilder();
sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)), Usage.Position | Usage.Normal);
// cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float) Gdx.graphics.getHeight()));
cam.near = 1;
cam.far = 200;
Random rand = new Random();
for (int i = 0; i < instances.length; i++) {
pos.set(rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * -100 - 3);
instances[i] = new ModelInstance(sphere, pos);
}
modelBatch = new ModelBatch();
batch = new SpriteBatch();
font = new BitmapFont();
// Gdx.graphics.setVSync(true);
// Gdx.app.log("CullTest", "" + Gdx.graphics.getBufferFormat().toString());
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class VoxelTest method create.
@Override
public void create() {
spriteBatch = new SpriteBatch();
font = new BitmapFont();
modelBatch = new ModelBatch();
DefaultShader.defaultCullFace = GL20.GL_FRONT;
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.near = 0.5f;
camera.far = 1000;
controller = new FirstPersonCameraController(camera);
Gdx.input.setInputProcessor(controller);
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
lights.add(new DirectionalLight().set(1, 1, 1, 0, -1, 0));
Texture texture = new Texture(Gdx.files.internal("data/g3d/tiles.png"));
TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32);
MathUtils.random.setSeed(0);
voxelWorld = new VoxelWorld(tiles[0], 20, 4, 20);
PerlinNoiseGenerator.generateVoxels(voxelWorld, 0, 63, 10);
float camX = voxelWorld.voxelsX / 2f;
float camZ = voxelWorld.voxelsZ / 2f;
float camY = voxelWorld.getHighest(camX, camZ) + 1.5f;
camera.position.set(camX, camY, camZ);
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class GwtTestWrapper method create.
@Override
public void create() {
Gdx.app.setLogLevel(Application.LOG_DEBUG);
Gdx.app.log("GdxTestGwt", "Setting up for " + tests.length + " tests.");
ui = new Stage();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
container = new Table();
ui.addActor(container);
container.debug();
Table table = new Table();
ScrollPane scroll = new ScrollPane(table);
container.add(scroll).expand().fill();
table.pad(10).defaults().expandX().space(4);
Arrays.sort(tests, new Comparator<Instancer>() {
@Override
public int compare(Instancer o1, Instancer o2) {
return o1.instance().getClass().getName().compareTo(o2.instance().getClass().getName());
}
});
for (final Instancer instancer : tests) {
table.row();
TextButton button = new TextButton(instancer.instance().getClass().getName(), skin);
button.addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
((InputWrapper) Gdx.input).multiplexer.removeProcessor(ui);
test = instancer.instance();
Gdx.app.log("GdxTestGwt", "Clicked on " + test.getClass().getName());
test.create();
test.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
});
table.add(button).expandX().fillX();
}
container.row();
container.add(new Label("Click on a test to start it, press ESC to close it.", new LabelStyle(font, Color.WHITE))).pad(5, 5, 5, 5);
Gdx.input = new InputWrapper(Gdx.input) {
@Override
public boolean keyUp(int keycode) {
if (keycode == Keys.ESCAPE) {
if (test != null) {
Gdx.app.log("GdxTestGwt", "Exiting current test.");
dispose = true;
}
}
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (screenX < Gdx.graphics.getWidth() / 10.0 && screenY < Gdx.graphics.getHeight() / 10.0) {
if (test != null) {
dispose = true;
}
}
return false;
}
};
((InputWrapper) Gdx.input).multiplexer.addProcessor(ui);
Gdx.app.log("GdxTestGwt", "Test picker UI setup complete.");
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class NetAPITest method create.
@Override
public void create() {
batch = new SpriteBatch();
skin = new Skin(Gdx.files.internal("data/uiskin.json"));
font = new BitmapFont();
stage = new Stage();
Gdx.input.setInputProcessor(stage);
{
statusLabel = new Label("", skin);
statusLabel.setWrap(true);
statusLabel.setWidth(Gdx.graphics.getWidth() * 0.96f);
statusLabel.setAlignment(Align.center);
statusLabel.setPosition(Gdx.graphics.getWidth() * 0.5f - statusLabel.getWidth() * 0.5f, 30f);
statusLabel.setColor(Color.CYAN);
stage.addActor(statusLabel);
}
{
ClickListener clickListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
clickedButton = event.getListenerActor();
setButtonDisabled(true);
if (texture != null)
texture.dispose();
texture = null;
text = null;
String url;
String httpMethod = Net.HttpMethods.GET;
String requestContent = null;
if (clickedButton == btnDownloadImage)
url = "http://i.imgur.com/vxomF.jpg";
else if (clickedButton == btnDownloadText)
url = "http://www.apache.org/licenses/LICENSE-2.0.txt";
else if (clickedButton == btnDownloadLarge)
url = "http://libgdx.badlogicgames.com/releases/libgdx-1.2.0.zip";
else if (clickedButton == btnDownloadError)
url = "http://www.badlogicgames.com/doesnotexist";
else if (clickedButton == btnOpenUri) {
Gdx.net.openURI("http://libgdx.badlogicgames.com/");
return;
} else {
url = "http://posttestserver.com/post.php?dump";
httpMethod = Net.HttpMethods.POST;
requestContent = "name1=value1&name2=value2";
}
httpRequest = new HttpRequest(httpMethod);
httpRequest.setUrl(url);
httpRequest.setContent(requestContent);
Gdx.net.sendHttpRequest(httpRequest, NetAPITest.this);
statusLabel.setText("Downloading data from " + httpRequest.getUrl());
}
};
ClickListener cancelListener = new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
super.clicked(event, x, y);
if (httpRequest != null) {
Gdx.net.cancelHttpRequest(httpRequest);
Gdx.app.log("NetAPITest", "Cancelling request " + httpRequest.getUrl());
statusLabel.setText("Cancelling request " + httpRequest.getUrl());
}
}
};
btnCancel = new TextButton("Cancel", skin);
btnCancel.setPosition(Gdx.graphics.getWidth() * 0.10f, 60f);
btnCancel.addListener(cancelListener);
stage.addActor(btnCancel);
btnDownloadImage = new TextButton("GET Image", skin);
btnDownloadImage.setPosition(btnCancel.getX() + btnCancel.getWidth() + 10, 60f);
btnDownloadImage.addListener(clickListener);
stage.addActor(btnDownloadImage);
btnDownloadText = new TextButton("GET Text", skin);
btnDownloadText.setPosition(btnDownloadImage.getX() + btnDownloadImage.getWidth() + 10, 60f);
btnDownloadText.addListener(clickListener);
stage.addActor(btnDownloadText);
btnDownloadLarge = new TextButton("GET Large", skin);
btnDownloadLarge.setPosition(btnDownloadText.getX() + btnDownloadText.getWidth() + 10, 60f);
btnDownloadLarge.addListener(clickListener);
stage.addActor(btnDownloadLarge);
btnDownloadError = new TextButton("GET Error", skin);
btnDownloadError.setPosition(btnDownloadLarge.getX() + btnDownloadLarge.getWidth() + 10, 60f);
btnDownloadError.addListener(clickListener);
stage.addActor(btnDownloadError);
btnPost = new TextButton("POST", skin);
btnPost.setPosition(btnDownloadError.getX() + btnDownloadError.getWidth() + 10, 60f);
btnPost.addListener(clickListener);
stage.addActor(btnPost);
btnOpenUri = new TextButton("Open URI", skin);
btnOpenUri.setPosition(btnPost.getX() + btnPost.getWidth() + 10, 60f);
btnOpenUri.addListener(clickListener);
stage.addActor(btnOpenUri);
}
}
use of com.badlogic.gdx.graphics.g2d.BitmapFont in project libgdx by libgdx.
the class UISimpleTest method create.
@Override
public void create() {
batch = new SpriteBatch();
stage = new Stage();
Gdx.input.setInputProcessor(stage);
// A skin can be loaded via JSON or defined programmatically, either is fine. Using a skin is optional but strongly
// recommended solely for the convenience of getting a texture, region, etc as a drawable, tinted drawable, etc.
skin = new Skin();
// Generate a 1x1 white texture and store it in the skin named "white".
Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
skin.add("white", new Texture(pixmap));
// Store the default libgdx font under the name "default".
skin.add("default", new BitmapFont());
// Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font.
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.down = skin.newDrawable("white", Color.DARK_GRAY);
textButtonStyle.checked = skin.newDrawable("white", Color.BLUE);
textButtonStyle.over = skin.newDrawable("white", Color.LIGHT_GRAY);
textButtonStyle.font = skin.getFont("default");
skin.add("default", textButtonStyle);
// Create a table that fills the screen. Everything else will go inside this table.
Table table = new Table();
table.setFillParent(true);
stage.addActor(table);
// Create a button with the "default" TextButtonStyle. A 3rd parameter can be used to specify a name other than "default".
final TextButton button = new TextButton("Click me!", skin);
table.add(button);
// Add a listener to the button. ChangeListener is fired when the button's checked state changes, eg when clicked,
// Button#setChecked() is called, via a key press, etc. If the event.cancel() is called, the checked state will be reverted.
// ClickListener could have been used, but would only fire when clicked. Also, canceling a ClickListener event won't
// revert the checked state.
button.addListener(new ChangeListener() {
public void changed(ChangeEvent event, Actor actor) {
System.out.println("Clicked! Is checked: " + button.isChecked());
button.setText("Good job!");
}
});
// Add an image actor. Have to set the size, else it would be the size of the drawable (which is the 1x1 texture).
table.add(new Image(skin.newDrawable("white", Color.RED))).size(64);
}
Aggregations