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

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

Introduction

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

Prototype

int GL_ONE_MINUS_SRC_ALPHA

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

Click Source Link

Usage

From source file:com.belocraft.gameworld.GameRenderer.java

private void drawTransition(float delta) {
    if (alpha.getValue() > 0) {
        manager.update(delta);/*w  w w.  j a va 2 s. co m*/
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        shapeRenderer.begin(ShapeType.Filled);
        shapeRenderer.setColor(1, 1, 1, alpha.getValue());
        shapeRenderer.rect(0, 0, 136, 300);
        shapeRenderer.end();
        Gdx.gl.glDisable(GL20.GL_BLEND);

    }
}

From source file:com.bladecoder.engine.util.Utils3D.java

License:Apache License

public static void createFloor() {

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();/* w ww .  j  a  va2s .  com*/
    MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal | Usage.ColorUnpacked,
            new Material(ColorAttribute.createDiffuse(Color.WHITE)));
    mpb.setColor(1f, 1f, 1f, 1f);
    //      mpb.box(0, -0.1f, 0, 10, .2f, 10);
    mpb.rect(-10, 0, -10, -10, 0, 10, 10, 0, 10, 10, 0, -10, 0, 1, 0);
    floorModel = modelBuilder.end();
    floorInstance = new ModelInstance(floorModel);

    // TODO Set only when FBO is active
    floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
}

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

License:Apache License

public void render(Matrix4 combined, float x1, float x2, float y1, float y2) {

    boolean needed = rayHandler.lightRenderedLastFrame > 0;
    // this way lot less binding
    if (needed && rayHandler.blur)
        gaussianBlur();//from   w w w  . jav a2  s.c om

    if (lightMapDrawingDisabled) {
        return;
    }
    frameBuffer.getColorBufferTexture().bind(0);

    // at last lights are rendered over scene
    if (rayHandler.shadows) {

        final Color c = rayHandler.ambientLight;
        ShaderProgram shader = shadowShader;
        if (RayHandler.isDiffuse) {
            shader = diffuseShader;
            shader.begin();
            Gdx.gl20.glBlendFunc(GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR);
            shader.setUniformf("ambient", c.r, c.g, c.b, c.a);
        } else {
            shader.begin();
            Gdx.gl20.glBlendFunc(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
            shader.setUniformf("ambient", c.r * c.a, c.g * c.a, c.b * c.a, 1f - c.a);
        }
        lightMapMesh.render(shader, GL20.GL_TRIANGLE_FAN);
        shader.end();
    } else if (needed) {

        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
        withoutShadowShader.begin();
        // withoutShadowShader.setUniformi("u_texture", 0);
        lightMapMesh.render(withoutShadowShader, GL20.GL_TRIANGLE_FAN);
        withoutShadowShader.end();
    }

    Gdx.gl20.glDisable(GL20.GL_BLEND);
}

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

License:Open Source License

@SuppressWarnings("null")
public void draw(PolygonSpriteBatch batch, Skeleton skeleton) {
    boolean premultipliedAlpha = this.premultipliedAlpha;
    int srcFunc = premultipliedAlpha ? GL20.GL_ONE : GL20.GL_SRC_ALPHA;
    batch.setBlendFunction(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA);

    boolean additive = false;

    float[] vertices = null;
    short[] triangles = null;
    Array<Slot> drawOrder = skeleton.drawOrder;
    for (int i = 0, n = drawOrder.size; i < n; i++) {
        Slot slot = drawOrder.get(i);//from w ww. j  av  a2  s . c  o m
        Attachment attachment = slot.attachment;
        Texture texture = null;
        if (attachment instanceof RegionAttachment) {
            RegionAttachment region = (RegionAttachment) attachment;
            region.updateWorldVertices(slot, premultipliedAlpha);
            vertices = region.getWorldVertices();
            triangles = quadTriangles;
            texture = region.getRegion().getTexture();

        } else if (attachment instanceof MeshAttachment) {
            MeshAttachment mesh = (MeshAttachment) attachment;
            mesh.updateWorldVertices(slot, premultipliedAlpha);
            vertices = mesh.getWorldVertices();
            triangles = mesh.getTriangles();
            texture = mesh.getRegion().getTexture();

        } else if (attachment instanceof SkinnedMeshAttachment) {
            SkinnedMeshAttachment mesh = (SkinnedMeshAttachment) attachment;
            mesh.updateWorldVertices(slot, premultipliedAlpha);
            vertices = mesh.getWorldVertices();
            triangles = mesh.getTriangles();
            texture = mesh.getRegion().getTexture();

        } else if (attachment instanceof SkeletonAttachment) {
            Skeleton attachmentSkeleton = ((SkeletonAttachment) attachment).getSkeleton();
            if (attachmentSkeleton == null)
                continue;
            Bone bone = slot.getBone();
            Bone rootBone = attachmentSkeleton.getRootBone();
            float oldScaleX = rootBone.getScaleX();
            float oldScaleY = rootBone.getScaleY();
            float oldRotation = rootBone.getRotation();
            attachmentSkeleton.setPosition(skeleton.getX() + bone.getWorldX(),
                    skeleton.getY() + bone.getWorldY());
            rootBone.setScaleX(1 + bone.getWorldScaleX() - oldScaleX);
            rootBone.setScaleY(1 + bone.getWorldScaleY() - oldScaleY);
            rootBone.setRotation(oldRotation + bone.getWorldRotation());
            attachmentSkeleton.updateWorldTransform();

            draw(batch, attachmentSkeleton);

            attachmentSkeleton.setPosition(0, 0);
            rootBone.setScaleX(oldScaleX);
            rootBone.setScaleY(oldScaleY);
            rootBone.setRotation(oldRotation);
        }

        if (texture != null) {
            if (slot.data.getAdditiveBlending() != additive) {
                additive = !additive;
                if (additive)
                    batch.setBlendFunction(srcFunc, GL20.GL_ONE);
                else
                    batch.setBlendFunction(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA);
            }
            batch.draw(texture, vertices, 0, vertices.length, triangles, 0, triangles.length);
        }
    }
}

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

License:Open Source License

public void draw(Batch batch, Skeleton skeleton) {
    boolean premultipliedAlpha = this.premultipliedAlpha;
    int srcFunc = premultipliedAlpha ? GL20.GL_ONE : GL20.GL_SRC_ALPHA;
    batch.setBlendFunction(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA);

    boolean additive = false;

    Array<Slot> drawOrder = skeleton.drawOrder;
    for (int i = 0, n = drawOrder.size; i < n; i++) {
        Slot slot = drawOrder.get(i);/*  www . j a va  2  s .c  o m*/
        Attachment attachment = slot.attachment;
        if (attachment instanceof RegionAttachment) {
            RegionAttachment regionAttachment = (RegionAttachment) attachment;
            regionAttachment.updateWorldVertices(slot, premultipliedAlpha);
            float[] vertices = regionAttachment.getWorldVertices();
            if (slot.data.getAdditiveBlending() != additive) {
                additive = !additive;
                if (additive)
                    batch.setBlendFunction(srcFunc, GL20.GL_ONE);
                else
                    batch.setBlendFunction(srcFunc, GL20.GL_ONE_MINUS_SRC_ALPHA);
            }
            batch.draw(regionAttachment.getRegion().getTexture(), vertices, 0, 20);

        } else if (attachment instanceof MeshAttachment || attachment instanceof SkinnedMeshAttachment) {
            throw new RuntimeException("PolygonSpriteBatch is required to render meshes.");

        } else if (attachment instanceof SkeletonAttachment) {
            Skeleton attachmentSkeleton = ((SkeletonAttachment) attachment).getSkeleton();
            if (attachmentSkeleton == null)
                continue;
            Bone bone = slot.getBone();
            Bone rootBone = attachmentSkeleton.getRootBone();
            float oldScaleX = rootBone.getScaleX();
            float oldScaleY = rootBone.getScaleY();
            float oldRotation = rootBone.getRotation();
            attachmentSkeleton.setPosition(skeleton.getX() + bone.getWorldX(),
                    skeleton.getY() + bone.getWorldY());
            rootBone.setScaleX(1 + bone.getWorldScaleX() - oldScaleX);
            rootBone.setScaleY(1 + bone.getWorldScaleY() - oldScaleY);
            rootBone.setRotation(oldRotation + bone.getWorldRotation());
            attachmentSkeleton.updateWorldTransform();

            draw(batch, attachmentSkeleton);

            attachmentSkeleton.setX(0);
            attachmentSkeleton.setY(0);
            rootBone.setScaleX(oldScaleX);
            rootBone.setScaleY(oldScaleY);
            rootBone.setRotation(oldRotation);
        }
    }
}

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);//  w  w  w .  j  av a2 s. co m
    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);
        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;//from w ww.  j ava2s . c o m
    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.BackgroundShader.java

License:Apache License

@Override
public void begin(Camera camera, RenderContext context) {
    context.setDepthTest(GL20.GL_NONE);//from   w ww.  j av a 2 s  . co m

    program.begin();
    viewProjTrans.set(camera.combined);

    context.setCullFace(GL20.GL_BACK);
    context.setBlending(false, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    texture.bind(0);
    program.setUniformi(u_texture, 0);

    program.setUniformf(u_color, color.r, color.g, color.b);
    program.setUniformf(u_ambient, MainRenderer.AMBIENT_BRIGHTNESS);
}

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

License:Apache License

@Override
public void begin(Camera camera, RenderContext context) {
    context.setDepthTest(GL20.GL_NONE);/*from   www  .j av a 2  s.c  o  m*/

    program.begin();
    viewProjTrans.set(camera.combined);

    context.setCullFace(GL20.GL_BACK);
    context.setBlending(false, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

}

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

License:Apache License

public void render() {
    batch.enableBlending();//  ww  w. j a v a 2s. c om
    batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    batch.begin();
    batch.setColor(Settings.filmGrain ? FILM_GRAIN_BRIGHTNESS : 0, Settings.scanLines ? SCANLINE_BRIGHTNESS : 0,
            Settings.vignette ? VIGNETTE_BRIGHTNESS : 0, 1);
    filmGrainShaderProgram.setUniformf(u_grainInverse, mFilmGrainInverse);
    filmGrainShaderProgram.setUniformf(u_scanLineInverse, mScanLineInverse);
    filmGrainShaderProgram.setUniformf(u_grainOffset, mRandom.nextFloat() * mFilmGrainInverse.x,
            mRandom.nextFloat() * mFilmGrainInverse.y);
    filmGrainShaderProgram.setUniformf(u_flicker, lerp(0.96f, 1f, mRandom.nextFloat()));
    noiseTexture.bind(1);
    scanlineTexture.bind(2);
    Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
    filmGrainShaderProgram.setUniformi(u_noiseTexture, 1);
    filmGrainShaderProgram.setUniformi(u_scanLineTexture, 2);
    batch.draw(borderTexture, -1, -1, 2, 2);
    batch.end();
}