Search in sources :

Example 1 with Decal

use of com.badlogic.gdx.graphics.g3d.decals.Decal in project libgdx by libgdx.

the class DecalTest method render.

@Override
public void render() {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    float elapsed = Gdx.graphics.getDeltaTime();
    float scale = timePassed > 0.5 ? 1 - timePassed / 2 : 0.5f + timePassed / 2;
    for (Decal decal : toRender) {
        decal.rotateZ(elapsed * 45);
        decal.setScale(scale);
        batch.add(decal);
    }
    batch.flush();
    timePassed += elapsed;
    frames++;
    if (timePassed > 1.0f) {
        System.out.println("DecalPerformanceTest2 fps: " + frames + " at spritecount: " + toRender.size());
        fps.addValue(frames);
        if (fps.hasEnoughData()) {
            float factor = fps.getMean() / (float) TARGET_FPS;
            int target = (int) (toRender.size() * factor);
            if (fps.getMean() > TARGET_FPS) {
                int start = toRender.size();
                for (int i = start; toRender.size() < target; i++) {
                    toRender.add(makeDecal());
                }
                fps.clear();
            } else {
                while (toRender.size() > target) {
                    toRender.removeLast();
                }
                fps.clear();
            }
        }
        timePassed = 0;
        frames = 0;
    }
}
Also used : Decal(com.badlogic.gdx.graphics.g3d.decals.Decal)

Example 2 with Decal

use of com.badlogic.gdx.graphics.g3d.decals.Decal in project libgdx by libgdx.

the class DecalTest method makeDecal.

private Decal makeDecal() {
    Decal sprite = null;
    switch(idx % 2) {
        case 0:
            sprite = Decal.newDecal(new TextureRegion(egg), willItBlend_that_is_the_question);
            break;
        case 1:
            sprite = Decal.newDecal(new TextureRegion(wheel));
            break;
    }
    sprite.setPosition(-w / 2 + (float) Math.random() * w, h / 2 - (float) Math.random() * h, (float) -Math.random() * 10);
    idx++;
    return sprite;
}
Also used : Decal(com.badlogic.gdx.graphics.g3d.decals.Decal) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion)

Example 3 with Decal

use of com.badlogic.gdx.graphics.g3d.decals.Decal in project libgdx by libgdx.

the class SimpleDecalTest method render.

public void render() {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
    camera.update();
    for (int i = 0; i < decals.size; i++) {
        Decal decal = decals.get(i);
        if (billboard) {
            // billboarding for ortho cam :)
            // dir.set(-camera.direction.x, -camera.direction.y, -camera.direction.z);
            // decal.setRotation(dir, Vector3.Y);
            // billboarding for perspective cam
            decal.lookAt(camera.position, camera.up);
        }
        batch.add(decal);
    }
    batch.flush();
    logger.log();
}
Also used : Decal(com.badlogic.gdx.graphics.g3d.decals.Decal)

Example 4 with Decal

use of com.badlogic.gdx.graphics.g3d.decals.Decal in project libgdx by libgdx.

the class SimpleDecalTest method create.

public void create() {
    float width = Gdx.graphics.getWidth();
    float height = Gdx.graphics.getHeight();
    camera = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.near = 1;
    camera.far = 300;
    camera.position.set(0, 0, 5);
    controller = new PerspectiveCamController(camera);
    Gdx.input.setInputProcessor(controller);
    batch = new DecalBatch(new CameraGroupStrategy(camera));
    TextureRegion[] textures = { new TextureRegion(new Texture(Gdx.files.internal("data/egg.png"))), new TextureRegion(new Texture(Gdx.files.internal("data/wheel.png"))), new TextureRegion(new Texture(Gdx.files.internal("data/badlogic.jpg"))) };
    Decal decal = Decal.newDecal(1, 1, textures[1]);
    decal.setPosition(0, 0, 0);
    decals.add(decal);
    decal = Decal.newDecal(1, 1, textures[0], true);
    decal.setPosition(0.5f, 0.5f, 1);
    decals.add(decal);
    decal = Decal.newDecal(1, 1, textures[0], true);
    decal.setPosition(1, 1, -1);
    decals.add(decal);
    decal = Decal.newDecal(1, 1, textures[2]);
    decal.setPosition(1.5f, 1.5f, -2);
    decals.add(decal);
    decal = Decal.newDecal(1, 1, textures[1]);
    decal.setPosition(2, 2, -1.5f);
    decals.add(decal);
}
Also used : DecalBatch(com.badlogic.gdx.graphics.g3d.decals.DecalBatch) Decal(com.badlogic.gdx.graphics.g3d.decals.Decal) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) PerspectiveCamController(com.badlogic.gdx.tests.utils.PerspectiveCamController) CameraGroupStrategy(com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) Texture(com.badlogic.gdx.graphics.Texture)

Aggregations

Decal (com.badlogic.gdx.graphics.g3d.decals.Decal)4 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)2 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 Texture (com.badlogic.gdx.graphics.Texture)1 CameraGroupStrategy (com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy)1 DecalBatch (com.badlogic.gdx.graphics.g3d.decals.DecalBatch)1 PerspectiveCamController (com.badlogic.gdx.tests.utils.PerspectiveCamController)1