Example usage for com.badlogic.gdx.graphics GL20 GL_BLEND

List of usage examples for com.badlogic.gdx.graphics GL20 GL_BLEND

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics GL20 GL_BLEND.

Prototype

int GL_BLEND

To view the source code for com.badlogic.gdx.graphics GL20 GL_BLEND.

Click Source Link

Usage

From source file:com.box2dLight.box2dLight.LightMap.java

License:Apache License

public void gaussianBlur() {

    Gdx.gl20.glDisable(GL20.GL_BLEND);
    for (int i = 0; i < rayHandler.blurNum; i++) {
        frameBuffer.getColorBufferTexture().bind(0);
        // horizontal
        pingPongBuffer.begin();//from  www. j  av a2 s .co m
        {
            blurShader.begin();
            // blurShader.setUniformi("u_texture", 0);
            blurShader.setUniformf("dir", 1f, 0f);
            lightMapMesh.render(blurShader, GL20.GL_TRIANGLE_FAN, 0, 4);
            blurShader.end();
        }
        pingPongBuffer.end();

        pingPongBuffer.getColorBufferTexture().bind(0);
        // vertical
        frameBuffer.begin();
        {
            blurShader.begin();
            // blurShader.setUniformi("u_texture", 0);
            blurShader.setUniformf("dir", 0f, 1f);
            lightMapMesh.render(blurShader, GL20.GL_TRIANGLE_FAN, 0, 4);
            blurShader.end();

        }
        frameBuffer.end();
    }

    Gdx.gl20.glEnable(GL20.GL_BLEND);

}

From source file:com.box2dLight.box2dLight.RayHandler.java

License:Apache License

/** Manual rendering method for all lights.
 * /*w  w w. j a v a2 s. com*/
 * NOTE! Remember to call updateRays if you use this method. * Remember setCombinedMatrix(Matrix4 combined) before drawing.
 * 
 * 
 * Don't call this inside of any begin/end statements. Call this method after you have rendered background but before UI. Box2d
 * bodies can be rendered before or after depending how you want x-ray light interact with bodies */
public void render() {

    lightRenderedLastFrame = 0;

    Gdx.gl.glDepthMask(false);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE);

    renderWithShaders();

}

From source file:com.bss.game.HelpScreen5.java

License:Apache License

public void draw() {
    GL20 gl = Gdx.gl;//from  w w w. j a  v  a2  s. c  o m
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    guiCam.update();

    game.batcher.setProjectionMatrix(guiCam.combined);
    game.batcher.disableBlending();
    game.batcher.begin();
    game.batcher.draw(helpRegion, 0, 0, 480, 800);
    game.batcher.end();

    game.batcher.enableBlending();
    game.batcher.begin();
    game.batcher.draw(Assets.arrow, 480, 100, -150, 100);
    game.batcher.end();

    gl.glDisable(GL20.GL_BLEND);
}

From source file:com.company.minery.utils.spine.SkeletonRendererDebug.java

License:Open Source License

public void draw(Skeleton skeleton) {
    float skeletonX = skeleton.getX();
    float skeletonY = skeleton.getY();

    Gdx.gl.glEnable(GL20.GL_BLEND);
    int srcFunc = premultipliedAlpha ? GL20.GL_ONE : GL20.GL_SRC_ALPHA;
    Gdx.gl.glBlendFunc(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA);

    ShapeRenderer shapes = this.shapes;

    Array<Bone> bones = skeleton.getBones();
    if (drawBones) {
        shapes.setColor(boneLineColor);/*from  w w w  .j a  v  a 2  s .c  o  m*/
        shapes.begin(ShapeType.Filled);
        for (int i = 0, n = bones.size; i < n; i++) {
            Bone bone = bones.get(i);
            if (bone.parent == null)
                continue;
            float x = skeletonX + bone.data.length * bone.m00 + bone.worldX;
            float y = skeletonY + bone.data.length * bone.m10 + bone.worldY;
            shapes.rectLine(skeletonX + bone.worldX, skeletonY + bone.worldY, x, y, boneWidth * scale);
        }
        shapes.end();
        shapes.begin(ShapeType.Line);
        shapes.x(skeletonX, skeletonY, 4 * scale);
    } else
        shapes.begin(ShapeType.Line);

    if (drawRegionAttachments) {
        shapes.setColor(attachmentLineColor);
        Array<Slot> slots = skeleton.getSlots();
        for (int i = 0, n = slots.size; i < n; i++) {
            Slot slot = slots.get(i);
            Attachment attachment = slot.attachment;
            if (attachment instanceof RegionAttachment) {
                RegionAttachment regionAttachment = (RegionAttachment) attachment;
                regionAttachment.updateWorldVertices(slot, false);
                float[] vertices = regionAttachment.getWorldVertices();
                shapes.line(vertices[X1], vertices[Y1], vertices[X2], vertices[Y2]);
                shapes.line(vertices[X2], vertices[Y2], vertices[X3], vertices[Y3]);
                shapes.line(vertices[X3], vertices[Y3], vertices[X4], vertices[Y4]);
                shapes.line(vertices[X4], vertices[Y4], vertices[X1], vertices[Y1]);
            }
        }
    }

    if (drawMeshHull || drawMeshTriangles) {
        Array<Slot> slots = skeleton.getSlots();
        for (int i = 0, n = slots.size; i < n; i++) {
            Slot slot = slots.get(i);
            Attachment attachment = slot.attachment;
            float[] vertices = null;
            short[] triangles = null;
            int hullLength = 0;
            if (attachment instanceof MeshAttachment) {
                MeshAttachment mesh = (MeshAttachment) attachment;
                mesh.updateWorldVertices(slot, false);
                vertices = mesh.getWorldVertices();
                triangles = mesh.getTriangles();
                hullLength = mesh.getHullLength();
            } else if (attachment instanceof SkinnedMeshAttachment) {
                SkinnedMeshAttachment mesh = (SkinnedMeshAttachment) attachment;
                mesh.updateWorldVertices(slot, false);
                vertices = mesh.getWorldVertices();
                triangles = mesh.getTriangles();
                hullLength = mesh.getHullLength();
            }
            if (vertices == null || triangles == null)
                continue;
            if (drawMeshTriangles) {
                shapes.setColor(triangleLineColor);
                for (int ii = 0, nn = triangles.length; ii < nn; ii += 3) {
                    int v1 = triangles[ii] * 5, v2 = triangles[ii + 1] * 5, v3 = triangles[ii + 2] * 5;
                    shapes.triangle(vertices[v1], vertices[v1 + 1], //
                            vertices[v2], vertices[v2 + 1], //
                            vertices[v3], vertices[v3 + 1] //
                    );
                }
            }
            if (drawMeshHull && hullLength > 0) {
                shapes.setColor(attachmentLineColor);
                hullLength = hullLength / 2 * 5;
                float lastX = vertices[hullLength - 5], lastY = vertices[hullLength - 4];
                for (int ii = 0, nn = hullLength; ii < nn; ii += 5) {
                    float x = vertices[ii], y = vertices[ii + 1];
                    shapes.line(x, y, lastX, lastY);
                    lastX = x;
                    lastY = y;
                }
            }
        }
    }

    if (drawBoundingBoxes) {
        SkeletonBounds bounds = this.bounds;
        bounds.update(skeleton, true);
        shapes.setColor(aabbColor);
        shapes.rect(bounds.getMinX(), bounds.getMinY(), bounds.getWidth(), bounds.getHeight());
        shapes.setColor(boundingBoxColor);
        Array<FloatArray> polygons = bounds.getPolygons();
        for (int i = 0, n = polygons.size; i < n; i++) {
            FloatArray polygon = polygons.get(i);
            shapes.polygon(polygon.items, 0, polygon.size);
        }
    }

    shapes.end();
    shapes.begin(ShapeType.Filled);

    if (drawBones) {
        shapes.setColor(boneOriginColor);
        for (int i = 0, n = bones.size; i < n; i++) {
            Bone bone = bones.get(i);
            shapes.setColor(Color.GREEN);
            shapes.circle(skeletonX + bone.worldX, skeletonY + bone.worldY, 3 * scale, 8);
        }
    }

    shapes.end();
}

From source file:com.cyphercove.dayinspace.shared.FullScreenFader.java

License:Apache License

public void render(float deltaTime) {
    if (!on && alpha == 0)
        return; //nothing to draw or update

    alpha += (on ? 1 : -1) * deltaTime / fadeTime;
    alpha = Math.max(0, Math.min(1, alpha));

    GL20 gl = Gdx.gl20;/* w  w  w  . j a  v a  2s .  c  om*/
    gl.glEnable(GL20.GL_BLEND);
    gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    color.a = Interpolation.fade.apply(alpha);

    shader.begin();
    shader.setUniformf(u_color, color);
    mesh.render(shader, GL20.GL_TRIANGLE_FAN);
    shader.end();

}

From source file:com.cyphercove.doublehelix.ParticleGroupStrategy.java

License:Apache License

@Override
public void beforeGroup(int group, Array<Decal> contents) {
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR);
    contents.sort(cameraSorter);//from  w  ww. j a  va2  s .  c om

    tmpColor.set(Settings.backgroundColor).lerp(Color.WHITE, WHITENESS);

    shader.begin();
    shader.setUniformMatrix("u_projTrans", camera.combined);
    shader.setUniformi("u_texture", 0);
    shader.setUniformf("u_baseColor", tmpColor);
}

From source file:com.cyphercove.doublehelix.ParticleGroupStrategy.java

License:Apache License

@Override
public void beforeBillboardGroup(int group, Array<BillboardDecal> contents) {
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_COLOR);
    contents.sort(billboardCameraSorter);

    tmpColor.set(Settings.backgroundColor).lerp(Color.WHITE, WHITENESS);

    billboardShader.begin();/* w  w w .jav a2  s . c  o  m*/
    billboardShader.setUniformMatrix("u_projTrans", camera.combined);
    billboardShader.setUniformi("u_texture", 0);
    billboardShader.setUniformf("u_baseColor", tmpColor);
}

From source file:com.cyphercove.lwptools.core.FullScreenFader.java

License:Apache License

public void render(float deltaTime) {
    if (elapsed >= fadeTime)
        return;//from  www.j  a v a2  s . c  o  m

    if (delay > 0) {
        delay -= deltaTime;
    }

    GL20 gl = Gdx.gl20;
    gl.glEnable(GL20.GL_BLEND);
    gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    color.a = delay > 0 ? 1f : 1f - Interpolation.fade.apply(elapsed / fadeTime);

    if (shader == null)
        createShader();
    shader.begin();
    shader.setUniformf(u_color, color);
    mesh.render(shader, GL20.GL_TRIANGLE_FAN);

    shader.end();

    if (delay <= 0)
        elapsed += deltaTime;
}

From source file:com.doom.render.QuadBatch.java

License:Apache License

@Override
public void end() {
    if (!drawing)
        throw new IllegalStateException("SpriteBatch.begin must be called before end.");
    if (idx > 0)
        flush();//from  www .j a va  2s  .c  om
    lastTexture = null;
    drawing = false;

    GL20 gl = Gdx.gl20;
    gl.glDepthMask(true);
    if (isBlendingEnabled())
        gl.glDisable(GL20.GL_BLEND);

    if (customShader != null)
        customShader.end();
    else
        shader.end();
}

From source file:com.doom.render.QuadBatch.java

License:Apache License

@Override
public void flush() {
    if (idx == 0)
        return;//from   ww w .j  av  a 2s.co  m

    renderCalls++;
    totalRenderCalls++;
    int spritesInBatch = idx / 20;
    if (spritesInBatch > maxSpritesInBatch)
        maxSpritesInBatch = spritesInBatch;
    int count = spritesInBatch * 6;

    lastTexture.bind();
    Mesh mesh = this.mesh;
    mesh.setVertices(vertices, 0, idx);
    mesh.getIndicesBuffer().position(0);
    mesh.getIndicesBuffer().limit(count);

    if (blendingDisabled) {
        Gdx.gl.glDisable(GL20.GL_BLEND);
    } else {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        if (blendSrcFunc != -1)
            Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc);
    }

    mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count);

    idx = 0;
}