Example usage for com.badlogic.gdx.graphics.g2d SpriteBatch disableBlending

List of usage examples for com.badlogic.gdx.graphics.g2d SpriteBatch disableBlending

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d SpriteBatch disableBlending.

Prototype

@Override
    public void disableBlending() 

Source Link

Usage

From source file:com.badlogic.gdx.tests.PremultiplyAlpha.java

private void gpuPremultiplyAlpha(String in, String out) {
    Texture texture = new Texture(Gdx.files.absolute(in));
    texture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, texture.getWidth(), texture.getHeight(), false);
    buffer.getColorBufferTexture().setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
    ShaderProgram shader = new ShaderProgram(VERTEX_SHADER, FRAG_SHADER);
    Gdx.app.log("Log", shader.getLog());
    SpriteBatch batch = new SpriteBatch(10);
    batch.getProjectionMatrix().setToOrtho2D(0, 0, texture.getWidth(), texture.getHeight());
    batch.disableBlending();
    batch.setShader(shader);/*from  w  w w.j a v  a  2 s  .  co  m*/

    //Premultiply
    buffer.begin();
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    batch.draw(texture, 0, 0);
    batch.end();
    Pixmap pixmap = ScreenUtils.getFrameBufferPixmap(0, 0, texture.getWidth(), texture.getHeight());
    buffer.end();

    //Save
    PixmapIO.writePNG(Gdx.files.absolute(out), pixmap);
    buffer.dispose();
    texture.dispose();
    pixmap.dispose();
    Gdx.app.exit();
}

From source file:com.bladecoder.engine.model.Scene.java

License:Apache License

public void draw(SpriteBatch batch) {

    if (background != null) {
        batch.disableBlending();
        batch.setProjectionMatrix(camera.calculateParallaxMatrix(1, 1));
        batch.begin();/*from  www  .  j a  va  2s  .  com*/

        float x = 0;

        for (AtlasRegion tile : background) {
            batch.draw(tile, x, 0f);
            x += tile.getRegionWidth();
        }

        batch.end();
        batch.enableBlending();
    }

    // draw layers from bottom to top
    for (int i = layers.size() - 1; i >= 0; i--) {
        SceneLayer layer = layers.get(i);

        batch.setProjectionMatrix(camera.calculateParallaxMatrix(layer.getParallaxMultiplier(), 1));
        batch.begin();
        layer.draw(batch);
        batch.end();
    }
}

From source file:com.jemge.j2d.Layer.java

License:Apache License

public void render(SpriteBatch spriteBatch, ShapeRenderer shapeRenderer) {
    this.cullingSystem.cull(Jemge.renderer2D.CAMERAVIEW);

    renderMode = Renderer2D.RenderMode.INACTIVE;
    ArrayList<IRendererObject> transparentObjects = new ArrayList<IRendererObject>();

    spriteBatch.disableBlending();
    renderMode = Renderer2D.RenderMode.DISABLED;

    for (IEntity entity : this.cullingSystem.getFinalRenderList()) {
        if (entity instanceof IShape) {
            ((IShape) entity).renderShape(shapeRenderer);
            continue;
        }/*from   w w  w  .j a v  a 2  s .c  o  m*/
        if (!(entity instanceof IRendererObject)) {
            continue;
        }

        if (((IRendererObject) entity).hasTransparent()) {
            transparentObjects.add((IRendererObject) entity);
            continue; // <- Continue if the object is translucent.
        }
        ((IRendererObject) entity).render(spriteBatch);

        if (entity instanceof Actor) {
            ((Actor) entity).draw(spriteBatch, 1.0f);
        }
    }

    for (Object object : this.RENDEREROBJECTS) {
        if (object instanceof IShape) {
            ((IShape) object).renderShape(shapeRenderer);
            continue;
        }
        if (!(object instanceof IRendererObject)) {
            continue;
        }

        if (((IRendererObject) object).hasTransparent()) {
            transparentObjects.add((IRendererObject) object);
            continue;
        }
        ((IRendererObject) object).render(spriteBatch);
    }

    // Now do the alpha pass:

    for (IRendererObject object : transparentObjects) {
        object.render(spriteBatch);
        if (object instanceof Actor)
            ((Actor) object).draw(spriteBatch, 1.0f);
    }

    this.cullingSystem.postRender();
}

From source file:org.bladecoder.bladeengine.model.Scene.java

License:Apache License

public void draw(SpriteBatch spriteBatch) {

    if (background != null) {
        spriteBatch.disableBlending();

        float x = 0;

        for (Texture tile : background) {
            spriteBatch.draw(tile, x, 0f);
            x += tile.getWidth();/*  w  ww. j av a  2 s  . c  o m*/
        }

        spriteBatch.enableBlending();
    }

    for (Actor a : orderedActors) {
        if (a instanceof SpriteActor)
            ((SpriteActor) a).draw(spriteBatch);
    }

    for (SpriteActor a : fgActors) {
        a.draw(spriteBatch);
    }

    // Draw the light map
    if (lightMap != null) {
        // Multiplicative blending for light maps
        spriteBatch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ZERO);

        float x = 0;

        for (Texture tile : lightMap) {
            spriteBatch.draw(tile, x, 0f);
            x += tile.getWidth();
        }

        spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    if (overlay != null) {
        overlay.draw(spriteBatch);
    }

    if (EngineLogger.debugMode() && EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) {

        StringBuilder sb = new StringBuilder();

        for (Actor a : orderedActors) {
            Rectangle r = a.getBBox().getBoundingRectangle();
            sb.setLength(0);
            sb.append(a.getId());
            if (a.getState() != null)
                sb.append(".").append(a.getState());
            // sb.append(" (").append((int) r.getX()).append(", ");
            // sb.append((int) r.getY()).append(", ").append((int)
            // r.getWidth());
            // sb.append(", ").append((int) r.getHeight()).append(") ");
            EngineLogger.getDebugFont().draw(spriteBatch, sb.toString(), r.getX(), r.getY());
        }

    }
}