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

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

Introduction

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

Prototype

int GL_ONE

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

Click Source Link

Usage

From source file:at.therefactory.jewelthief.ui.Particles.java

License:Open Source License

/**
 * if particle effect includes additive or pre-multiplied particle emitters
 * you can turn off blend function clean-up to save a lot of draw calls
 * but remember to switch the Batch back to GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
 * before drawing "regular" sprites or your Stage.
 *
 * @param batch/*from ww w .  ja  va 2  s. co m*/
 */
private void resetBlendFunction(SpriteBatch batch) {
    batch.setBlendFunction(-1, -1);
    Gdx.gl20.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE,
            GL20.GL_DST_ALPHA);
}

From source file:com.badlogic.invaders.screens.GameOver.java

License:Apache License

@Override
public void draw(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    viewMatrix.setToOrtho2D(0, 0, 480, 320);
    spriteBatch.setProjectionMatrix(viewMatrix);
    spriteBatch.setTransformMatrix(transformMatrix);
    spriteBatch.begin();/*  w  w  w .  j  av  a 2 s.  c  o m*/
    spriteBatch.disableBlending();
    spriteBatch.setColor(Color.WHITE);
    spriteBatch.draw(background, 0, 0, 480, 320, 0, 0, 512, 512, false, false);
    spriteBatch.enableBlending();
    spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 256, 512, 256, false, false);
    String text = "It is the end my friend.\nTouch to continue!";
    TextBounds bounds = font.getMultiLineBounds(text);
    spriteBatch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    font.drawMultiLine(spriteBatch, text, 0, 160 + bounds.height / 2, 480, HAlignment.CENTER);
    spriteBatch.end();
}

From source file:com.badlogic.invaders.screens.MainMenu.java

License:Apache License

@Override
public void draw(float delta) {
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    viewMatrix.setToOrtho2D(0, 0, 480, 320);
    spriteBatch.setProjectionMatrix(viewMatrix);
    spriteBatch.setTransformMatrix(transformMatrix);
    spriteBatch.begin();/*w  w w. j  ava2  s  . c  o m*/
    spriteBatch.disableBlending();
    spriteBatch.setColor(Color.WHITE);
    spriteBatch.draw(background, 0, 0, 480, 320, 0, 0, 512, 512, false, false);
    spriteBatch.enableBlending();
    spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 0, 512, 256, false, false);
    spriteBatch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    String text = "Touch screen to start!";
    float width = font.getBounds(text).width;
    font.draw(spriteBatch, text, 240 - width / 2, 128);
    if (Gdx.app.getType() == ApplicationType.WebGL) {
        text = "Press Enter for Fullscreen Mode";
        width = font.getBounds(text).width;
        font.draw(spriteBatch, "Press Enter for Fullscreen Mode", 240 - width / 2, 128 - font.getLineHeight());
    }
    spriteBatch.end();
}

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);//from  w w w.j ava  2 s. com
        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();//  ww w  . ja  v  a  2  s.  c  o  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.
 * // www .  ja  v a  2  s . c  o  m
 * 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  a va  2 s.  co 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 ww  w  . j  a va2s. 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);//www  .j a v  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.doublehelix.FilmGrain.java

License:Apache License

public void render() {
    batch.enableBlending();/*from ww  w .  j a  va2  s .c o  m*/
    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();
}