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

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

Introduction

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

Prototype

int GL_SRC_ALPHA

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

Click Source Link

Usage

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

License:Apache License

public static void createFloor() {

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();/*from  w ww .j  av  a  2  s.  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.bmnb.fly_dragonfly.graphics.GameParticleEmitter.java

License:Apache License

/** Updates and draws the particles. This is slightly more efficient than calling {@link #update(float)} and
 * {@link #draw(SpriteBatch)} separately. */
public void draw(SpriteBatch spriteBatch, float delta) {
    accumulator += Math.min(delta * 1000, 250);
    if (accumulator < 1) {
        draw(spriteBatch);/*  www  .ja  v  a2  s.  c o  m*/
        return;
    }

    //      com.badlogic.gdx.graphics.g2d.ParticleEmitter

    int deltaMillis = (int) accumulator;
    accumulator -= deltaMillis;

    if (additive)
        spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);

    Particle[] particles = this.particles;
    boolean[] active = this.active;
    int activeCount = this.activeCount;
    for (int i = 0, n = active.length; i < n; i++) {
        if (active[i]) {
            Particle particle = particles[i];
            if (updateParticle(particle, delta, deltaMillis) && !particle.isDead())
                particle.draw(spriteBatch);
            else {
                particle.kill();
                active[i] = false;
                activeCount--;
            }
        }
    }
    this.activeCount = activeCount;

    if (additive)
        spriteBatch.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    if (delayTimer < delay) {
        delayTimer += deltaMillis;
        return;
    }

    if (firstUpdate) {
        firstUpdate = false;
        addParticle();
    }

    if (durationTimer < duration)
        durationTimer += deltaMillis;
    else {
        if (!continuous || allowCompletion)
            return;
        restart();
    }

    emissionDelta += deltaMillis;
    float emissionTime = emission + emissionDiff * emissionValue.getScale(durationTimer / (float) duration);
    if (emissionTime > 0) {
        emissionTime = 1000 / emissionTime;
        if (emissionDelta >= emissionTime) {
            int emitCount = (int) (emissionDelta / emissionTime);
            emitCount = Math.min(emitCount, maxParticleCount - activeCount);
            emissionDelta -= emitCount * emissionTime;
            emissionDelta %= emissionTime;
            addParticles(emitCount);
        }
    }
    if (activeCount < minParticleCount)
        addParticles(minParticleCount - activeCount);
}

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();/*w  ww  .j a  v a2s  .  co m*/

    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.box2dLight.box2dLight.RayHandler.java

License:Apache License

/** Manual rendering method for all lights.
 * /*w  w w. j ava  2 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.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);// w  w  w  .  j  ava  2s.  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);/*from   www.java 2 s  .  co  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.jav a  2  s .  c om*/
    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;/*www  .  j ava 2  s  .  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);/*w  w  w .  j  a  v a  2 s.c  om*/

    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);// w ww. ja  v 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);

}