Example usage for com.badlogic.gdx.graphics.g3d.decals DecalBatch DecalBatch

List of usage examples for com.badlogic.gdx.graphics.g3d.decals DecalBatch DecalBatch

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d.decals DecalBatch DecalBatch.

Prototype

public DecalBatch(GroupStrategy groupStrategy) 

Source Link

Document

Creates a new DecalBatch using the given GroupStrategy .

Usage

From source file:com.github.fauu.helix.core.Renderer.java

License:Open Source License

public void render(Camera camera, Array<RenderableProvider> renderableProviders, Array<Decal> decals) {
    final GL20 gl = Gdx.graphics.getGL20();

    gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL20.GL_BLEND);// ww  w  .  ja  va 2  s.c o m
    gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    if (decalBatch == null) {
        defaultCameraGroupStrategy = new CameraGroupStrategy(camera);
        waterCameraGroupStrategy = new CameraGroupStrategy(waterCamera);

        decalBatch = new DecalBatch(defaultCameraGroupStrategy);
    }

    //waterCamera.moveTo(new Vector2(13, 19));
    /* Render objects to framebuffer */
    fb.begin();
    gl.glClearColor(0, 0, 0, 0);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL20.GL_BLEND);
    gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    renderContext.begin();
    modelBatch.begin(waterCamera);
    for (int i = 1; i < renderableProviders.size - 1; i++) {
        modelBatch.render(renderableProviders.get(i));
    }
    modelBatch.end();
    renderContext.end();

    decalBatch.setGroupStrategy(waterCameraGroupStrategy);
    if (decals != null) {
        decals.first().rotateX(50);
        decalBatch.add(decals.first());
        decalBatch.flush();
        decals.first().rotateX(-50);
    }

    //    Vector3 waterPos = waterCamera.project(new Vector3(8, 0, 19));
    //    reflectionPixmap = ScreenUtils.getFrameBufferPixmap((int) waterPos.x, (int) waterPos.y, 348, 261);
    //    reflectionPixmap = ScreenUtils.getFrameBufferPixmap(0, 0, 800, 600);

    fb.end();

    //    if (reflectionTexture == null) {
    //      reflectionTexture = new Texture(reflectionPixmap);
    //    } else {
    //      reflectionTexture.draw(reflectionPixmap, 0, 0);
    //    }

    ((WaterData) ((ModelInstance) renderableProviders
            .get(renderableProviders.size - 1)).userData).reflectionTexture = fb.getColorBufferTexture();

    /* Render objects and terrain to the screen */
    renderContext.begin();
    modelBatch.begin(camera);
    modelBatch.render(renderableProviders);
    modelBatch.end();
    renderContext.end();
    decalBatch.setGroupStrategy(defaultCameraGroupStrategy);
    if (decals != null) {
        decalBatch.add(decals.first());
    }
    decalBatch.flush();

    spriteBatch.begin();
    spriteBatch.enableBlending();
    spriteBatch.draw(fb.getColorBufferTexture(), 0, 0, 800, 600);
    spriteBatch.end();

}

From source file:com.github.fauu.helix.system.RenderingSystem.java

License:Open Source License

@Override
protected void initialize() {
    displayableCollections = new Array<Array<? extends Displayable>>();

    modelDisplayables = new Array<ModelDisplayable>();
    displayableCollections.add(modelDisplayables);

    decalDisplayables = new Array<DecalDisplayable>();
    displayableCollections.add(decalDisplayables);

    renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.WEIGHTED));
    renderContext.setCullFace(GL20.GL_BACK);

    modelBatch = new ModelBatch(renderContext, new DefaultShaderProvider(), new HelixRenderableSorter());

    decalBatch = new DecalBatch(new CameraGroupStrategy(camera));

    spriteBatch = new SpriteBatch();
}