Search in sources :

Example 21 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class OcclusionCullingTest method create.

@Override
public void create() {
    Gdx.input.setOnscreenKeyboardVisible(true);
    super.create();
    GLProfiler.enable();
    StringBuilder sb = new StringBuilder();
    sb.append("Swipe for next test\n");
    sb.append("Long press to toggle debug mode\n");
    sb.append("Ctrl+drag to rotate\n");
    sb.append("Scroll to zoom\n");
    sb.append("Tap to spawn dynamic entity, press\n");
    sb.append("'0' to spawn ").append(KEY_SPAWN_OCCLUDEE_AMOUNT).append(" static entities\n");
    sb.append("'1' to set normal/disabled/occlusion-culling\n");
    sb.append("'2' to change camera\n");
    sb.append("'3' to toggle camera movement\n");
    sb.append("'4' to cycle occlusion buffer sizes\n");
    sb.append("'5' to toggle occlusion buffer image\n");
    sb.append("'6' to toggle shadows\n");
    instructions = sb.toString();
    AssetManager assets = new AssetManager();
    disposables.add(assets);
    for (String modelName : OCCLUDEE_PATHS_DYNAMIC) assets.load(modelName, Model.class);
    assets.load(DEFAULT_TEX_PATH, Texture.class);
    Camera shadowCamera = ((DirectionalShadowLight) light).getCamera();
    shadowCamera.viewportWidth = shadowCamera.viewportHeight = 120;
    // User controlled camera
    overviewCam = camera;
    overviewCam.position.set(overviewCam.direction).nor().scl(-100);
    overviewCam.lookAt(Vector3.Zero);
    overviewCam.far = camera.far *= 2;
    overviewCam.update(true);
    // Animated frustum camera model
    frustumCam = new PerspectiveCamera(FRUSTUM_CAMERA_FOV, camera.viewportWidth, camera.viewportHeight);
    frustumCam.far = FRUSTUM_CAMERA_FAR;
    frustumCam.update(true);
    final Model frustumModel = FrustumCullingTest.createFrustumModel(frustumCam.frustum.planePoints);
    frustumModel.materials.first().set(new ColorAttribute(ColorAttribute.AmbientLight, Color.WHITE));
    disposables.add(frustumModel);
    frustumInstance = new ModelInstance(frustumModel);
    spriteBatch = new SpriteBatch();
    disposables.add(spriteBatch);
    shapeRenderer = new ShapeRenderer();
    disposables.add(shapeRenderer);
    oclBuffer = new OcclusionBuffer(OCL_BUFFER_EXTENTS[0], OCL_BUFFER_EXTENTS[0]);
    disposables.add(oclBuffer);
    occlusionCuller = new OcclusionCuller() {

        @Override
        public boolean isOccluder(btCollisionObject object) {
            return (object.getCollisionFlags() & CF_OCCLUDER_OBJECT) != 0;
        }

        @Override
        public void onObjectVisible(btCollisionObject object) {
            visibleEntities.add(world.entities.get(object.getUserValue()));
        }
    };
    disposables.add(occlusionCuller);
    // Add occluder walls
    final Model occluderModel = modelBuilder.createBox(OCCLUDER_DIM.x, OCCLUDER_DIM.y, OCCLUDER_DIM.z, new Material(ColorAttribute.createDiffuse(Color.WHITE)), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    disposables.add(occluderModel);
    world.addConstructor("wall", new BulletConstructor(occluderModel, 0, new btBoxShape(tmpV1.set(OCCLUDER_DIM).scl(0.5f))));
    float y = OCCLUDER_DIM.y * 0.5f;
    addOccluder("wall", 0, tmpV1.set(20, y, 0));
    addOccluder("wall", -60, tmpV1.set(10, y, 20));
    addOccluder("wall", 60, tmpV1.set(10, y, -20));
    addOccluder("wall", 0, tmpV1.set(-20, y, 0));
    addOccluder("wall", 60, tmpV1.set(-10, y, 20));
    addOccluder("wall", -60, tmpV1.set(-10, y, -20));
    // Add ground
    final Model groundModel = modelBuilder.createBox(GROUND_DIM.x, GROUND_DIM.y, GROUND_DIM.z, new Material(ColorAttribute.createDiffuse(Color.WHITE)), VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal);
    btCollisionShape groundShape = new btBoxShape(tmpV1.set(GROUND_DIM).scl(0.5f));
    world.addConstructor("big_ground", new BulletConstructor(groundModel, 0, groundShape));
    BulletEntity e = world.add("big_ground", 0, -GROUND_DIM.y * 0.5f, 0f);
    e.body.setFriction(1f);
    e.setColor(Color.FOREST);
    // Occludee entity constructors. Scale models uniformly and set a default diffuse texture.
    BoundingBox bb = new BoundingBox();
    assets.finishLoadingAsset(DEFAULT_TEX_PATH);
    TextureAttribute defaultTexture = new TextureAttribute(TextureAttribute.Diffuse, assets.get(DEFAULT_TEX_PATH, Texture.class));
    for (int i = 0; i < OCCLUDEE_PATHS_DYNAMIC.length; i++) {
        String modelPath = OCCLUDEE_PATHS_DYNAMIC[i];
        OCCLUDEE_PATHS_STATIC[i] = "static" + modelPath;
        assets.finishLoadingAsset(modelPath);
        Model model = assets.get(modelPath, Model.class);
        if (!model.materials.first().has(TextureAttribute.Diffuse))
            model.materials.first().set(defaultTexture);
        Vector3 dim = model.calculateBoundingBox(bb).getDimensions(tmpV1);
        float scaleFactor = OCCLUDEE_MAX_EXTENT / Math.max(dim.x, Math.max(dim.y, dim.z));
        for (Node node : model.nodes) node.scale.scl(scaleFactor);
        btCollisionShape shape = new btBoxShape(dim.scl(scaleFactor * 0.5f));
        world.addConstructor(modelPath, new BulletConstructor(model, 1, shape));
        world.addConstructor(OCCLUDEE_PATHS_STATIC[i], new BulletConstructor(model, 0, shape));
    }
    // Add occludees
    for (int i = 0; i < STARTING_OCCLUDEE_AMOUNT; i++) addRandomOccludee(false);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) StringBuilder(com.badlogic.gdx.utils.StringBuilder) Node(com.badlogic.gdx.graphics.g3d.model.Node) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Texture(com.badlogic.gdx.graphics.Texture) com.badlogic.gdx.physics.bullet.collision.btCollisionShape(com.badlogic.gdx.physics.bullet.collision.btCollisionShape) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Camera(com.badlogic.gdx.graphics.Camera) com.badlogic.gdx.physics.bullet.collision.btCollisionObject(com.badlogic.gdx.physics.bullet.collision.btCollisionObject) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute) AssetManager(com.badlogic.gdx.assets.AssetManager) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) Model(com.badlogic.gdx.graphics.g3d.Model) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 22 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class BitmapFontTest method create.

@Override
public void create() {
    spriteBatch = new SpriteBatch();
    // font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false);
    font = new BitmapFont(Gdx.files.internal("data/arial-32-pad.fnt"), false);
    // font = new FreeTypeFontGenerator(Gdx.files.internal("data/arial.ttf")).generateFont(new FreeTypeFontParameter());
    font.getData().markupEnabled = true;
    font.getData().breakChars = new char[] { '-' };
    multiPageFont = new BitmapFont(Gdx.files.internal("data/multipagefont.fnt"));
    // Add user defined color
    Colors.put("PERU", Color.valueOf("CD853F"));
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix());
    stage = new Stage(new ScreenViewport());
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    BitmapFont labelFont = skin.get("default-font", BitmapFont.class);
    labelFont.getData().markupEnabled = true;
    // Notice that the last [] has been deliberately added to test the effect of excessive pop operations.
    // They are silently ignored, as expected.
    label = new Label("<<[BLUE]M[RED]u[YELLOW]l[GREEN]t[OLIVE]ic[]o[]l[]o[]r[]*[MAROON]Label[][] [Unknown Color]>>", skin);
    label.setPosition(100, 200);
    stage.addActor(label);
    Window window = new Window("[RED]Multicolor[GREEN] Title", skin);
    window.setPosition(400, 300);
    window.pack();
    stage.addActor(window);
    layout = new GlyphLayout();
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) GlyphLayout(com.badlogic.gdx.graphics.g2d.GlyphLayout) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 23 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class LabelTest method create.

@Override
public void create() {
    batch = new SpriteBatch();
    renderer = new ShapeRenderer();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    skin.getAtlas().getTextures().iterator().next().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    skin.getFont("default-font").getData().markupEnabled = true;
    float scale = 1;
    skin.getFont("default-font").getData().setScale(scale);
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);
    Table table = new Table();
    stage.addActor(table);
    table.setPosition(200, 65);
    table.debug();
    table.add(new Label("This is regular text.", skin));
    table.row();
    table.add(new Label("This is regular text\nwith a newline.", skin));
    table.row();
    Label label3 = new Label("This is [RED]regular text\n\nwith newlines,\naligned bottom, right.", skin);
    label3.setColor(Color.GREEN);
    label3.setAlignment(Align.bottom | Align.right);
    table.add(label3).minWidth(200 * scale).minHeight(110 * scale).fill();
    table.row();
    Label label4 = new Label("This is regular text with NO newlines, wrap enabled and aligned bottom, right.", skin);
    label4.setWrap(true);
    label4.setAlignment(Align.bottom | Align.right);
    table.add(label4).minWidth(200 * scale).minHeight(110 * scale).fill();
    table.row();
    Label label5 = new Label("This is regular text with\n\nnewlines, wrap\nenabled and aligned bottom, right.", skin);
    label5.setWrap(true);
    label5.setAlignment(Align.bottom | Align.right);
    table.add(label5).minWidth(200 * scale).minHeight(110 * scale).fill();
    table.pack();
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 24 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class MultitouchTest method create.

@Override
public void create() {
    Gdx.app.log("Multitouch", "multitouch supported: " + Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen));
    renderer = new ShapeRenderer();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(Gdx.graphics.getWidth() / 2.0f, Gdx.graphics.getHeight() / 2.0f, 0);
    Gdx.input.setInputProcessor(this);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 25 with ShapeRenderer

use of com.badlogic.gdx.graphics.glutils.ShapeRenderer in project libgdx by libgdx.

the class InverseKinematicsTest method create.

@Override
public void create() {
    float aspect = Gdx.graphics.getWidth() / (float) Gdx.graphics.getHeight();
    camera = new OrthographicCamera(15 * aspect, 15);
    camera.update();
    renderer = new ShapeRenderer();
    renderer.setProjectionMatrix(camera.combined);
    bones = new Bone[] { new Bone("bone0", 0, 0, 0), new Bone("bone1", 0, 2, 2), new Bone("bone2", 0, 4, 2), new Bone("bone3", 0, 6, 2), new Bone("end", 0, 8, 2) };
    globalCoords.set(bones[0].position);
}
Also used : OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Aggregations

ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)31 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)16 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)12 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)10 Texture (com.badlogic.gdx.graphics.Texture)8 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)7 Stage (com.badlogic.gdx.scenes.scene2d.Stage)5 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)5 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)5 InputAdapter (com.badlogic.gdx.InputAdapter)4 AssetManager (com.badlogic.gdx.assets.AssetManager)4 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)3 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)3 Model (com.badlogic.gdx.graphics.g3d.Model)3 TmxMapLoader (com.badlogic.gdx.maps.tiled.TmxMapLoader)3 Animation (com.badlogic.gdx.graphics.g2d.Animation)2 BitmapFontCache (com.badlogic.gdx.graphics.g2d.BitmapFontCache)2 FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)2 FreeTypeFontParameter (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter)2 OrthogonalTiledMapRenderer (com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer)2