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.github.fauu.helix.displayable.CharacterDisplayable.java

License:Open Source License

public CharacterDisplayable(IntVector3 logicalPosition, String animationSetName, TextureRegion shadowTexture) {
    super(logicalPosition.toVector3().add(DEFAULT_DISPLACEMENT));

    animations = new AnimationSet(animationSetName);

    AnimatedDecal decal = AnimatedDecal.newAnimatedDecal(DEFAULT_DIMENSIONS.x, DEFAULT_DIMENSIONS.y,
            animations.getDefault(), true);

    decal.setKeepSize(true);//w w  w  .  j a  va2s  .  c o m
    decal.setPosition(position);
    decal.rotateX(DEFAULT_ROTATION);

    setMainDecal(decal);

    Decal shadow = new Decal();

    shadow.setPosition(position);
    shadow.translate(DEFAULT_SHADOW_DISPLACEMENT);
    shadow.setDimensions(DEFAULT_SHADOW_DIMENSIONS.x, DEFAULT_SHADOW_DIMENSIONS.y);
    shadow.setColor(1, 1, 1, .35f);
    shadow.setTextureRegion(shadowTexture);
    shadow.setBlending(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    setShadowDecal(shadow);
}

From source file:com.github.fauu.helix.editor.displayable.TileHighlightDisplayable.java

License:Open Source License

public TileHighlightDisplayable() {
    ModelBuilder modelBuilder = new ModelBuilder();

    Model model = modelBuilder.createRect(0, 0, Z_OFFSET, 1, 0, Z_OFFSET, 1, 1, Z_OFFSET, 0, 1, Z_OFFSET, 0, 0,
            1, GL20.GL_TRIANGLES,/*from  w  w w  .  j a  va 2 s  .  co  m*/
            new Material(new ColorAttribute(ColorAttribute.createDiffuse(color)),
                    new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates);

    instance = new ModelInstance(model);
}

From source file:com.github.fauu.helix.game.Game.java

License:Open Source License

@Override
public void create() {
    camera = new Camera(new Vector3(32, 32, 0));

    cameraInputController = new CameraInputController(camera);
    //    Gdx.input.setInputProcessor(cameraInputController);

    assets = new AssetManager();
    assets.setLoader(GeometrySet.class, new GeometrySetLoader(new InternalFileHandleResolver()));
    assets.setLoader(MapRegion.class, new MapRegionLoader(new InternalFileHandleResolver()));
    assets.load("assets/mapregions/0.hmr", MapRegion.class);
    assets.finishLoading();//from   ww w  . j  ava  2 s.  com

    mapRegion = assets.get("assets/mapregions/0.hmr", MapRegion.class);

    spriteBatch = new SpriteBatch();

    renderer = new Renderer();

    player = new Player(new Vector2(8, 17), new Texture(Gdx.files.internal("assets/sprites/player.png")));
    camera.move(player.getRealPosition());

    final ModelBuilder modelBuilder = new ModelBuilder();

    waterTexture = new Texture("assets/textures/water.png");

    final MeshPartBuilder.VertexInfo corner00 = new MeshPartBuilder.VertexInfo();
    corner00.hasPosition = true;
    corner00.hasNormal = true;
    corner00.hasUV = true;
    corner00.setPos(0, 0, 0);
    corner00.setNor(0, 1, 0);
    corner00.setUV(0, 0);

    final MeshPartBuilder.VertexInfo corner10 = new MeshPartBuilder.VertexInfo();
    corner10.hasPosition = true;
    corner10.hasNormal = true;
    corner10.hasUV = true;
    corner10.setPos(4, 0, 0);
    corner10.setNor(0, 1, 0);
    corner10.setUV(0, 1);

    final MeshPartBuilder.VertexInfo corner11 = new MeshPartBuilder.VertexInfo();
    corner11.hasPosition = true;
    corner11.hasNormal = true;
    corner11.hasUV = true;
    corner11.setPos(4, 0, 14);
    corner11.setNor(0, 1, 0);
    corner11.setUV(1, 1);

    final MeshPartBuilder.VertexInfo corner01 = new MeshPartBuilder.VertexInfo();
    corner01.hasPosition = true;
    corner01.hasNormal = true;
    corner01.hasUV = true;
    corner01.setPos(0, 0, 14);
    corner01.setNor(0, 1, 0);
    corner01.setUV(1, 0);

    modelBuilder.begin();
    modelBuilder.node();
    MeshPartBuilder meshPartBuilder = modelBuilder.part("water1", GL20.GL_TRIANGLES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates,
            new Material(TextureAttribute.createDiffuse(waterTexture),
                    ColorAttribute.createDiffuse(Color.WHITE),
                    new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)));
    meshPartBuilder.rect(corner00, corner10, corner11, corner01);

    waterModel = modelBuilder.end();

    waterModelInstance = new ModelInstance(waterModel);
    WaterData waterData = new WaterData();
    waterData.waveAmplitude = 0.02f;
    waterData.waveAngle = 0;
    waterData.waveFrequency = 0.5f;
    waterModelInstance.userData = waterData;
    //    waterModelInstance.userData = new float[2];
    //    ((float[]) waterModelInstance.userData)[0] = 0; // waveAngle
    //    ((float[]) waterModelInstance.userData)[1] = 0.1f; // waveAmplitude

    waterModelInstance.transform.translate(8, -0.1f, 19).rotate(0, 1, 0, -90).scale(1, 1, -1);
    //    ((float[]) waterModelInstance.userData)[2] = 8; // startX
    //    ((float[]) waterModelInstance.userData)[3] = 7; // sizeX
    //    ((float[]) waterModelInstance.userData)[4] = 19; // startZ
    //    ((float[]) waterModelInstance.userData)[5] = 5; // sizeZ
}

From source file:com.github.fauu.helix.graphics.AnimatedDecal.java

License:Apache License

/** @see Decal#newDecal(TextureRegion, boolean) */
public static AnimatedDecal newDecal(Animation animation, boolean hasTransparency) {
    return newAnimatedDecal(animation.getKeyFrame(0).getRegionWidth(),
            animation.getKeyFrame(0).getRegionHeight(), animation,
            hasTransparency ? GL20.GL_SRC_ALPHA : DecalMaterial.NO_BLEND,
            hasTransparency ? GL20.GL_ONE_MINUS_SRC_ALPHA : DecalMaterial.NO_BLEND);
}

From source file:com.github.fauu.helix.graphics.AnimatedDecal.java

License:Apache License

/** @see Decal#newDecal(float, float, TextureRegion, boolean) */
public static AnimatedDecal newAnimatedDecal(float width, float height, Animation animation,
        boolean hasTransparency) {
    return newAnimatedDecal(width, height, animation,
            hasTransparency ? GL20.GL_SRC_ALPHA : DecalMaterial.NO_BLEND,
            hasTransparency ? GL20.GL_ONE_MINUS_SRC_ALPHA : DecalMaterial.NO_BLEND);
}

From source file:com.github.fauu.helix.graphics.ParticleEmitter.java

License:Apache License

public void draw(Batch batch) {
    if (premultipliedAlpha) {
        batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    } else if (additive) {
        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
    } else {//from  w ww .  j a v a  2  s.  c  om
        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
    Particle[] particles = this.particles;
    boolean[] active = this.active;

    for (int i = 0, n = active.length; i < n; i++) {
        if (active[i])
            particles[i].draw(batch);
    }

    if (cleansUpBlendFunction && (additive || premultipliedAlpha))
        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

}

From source file:com.github.fauu.helix.graphics.ParticleEmitter.java

License:Apache License

/** Updates and draws the particles. This is slightly more efficient than calling {@link #update(float, float, float)} and
 * {@link #draw(batch)} separately. */
public void draw(Batch batch, float delta) {
    accumulator += delta * 1000;//from w w w .  jav  a  2 s . co  m
    if (accumulator < 1) {
        draw(batch);
        return;
    }
    int deltaMillis = (int) accumulator;
    accumulator -= deltaMillis;

    if (premultipliedAlpha) {
        batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    } else if (additive) {
        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
    } else {
        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    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, 0, 0, delta, deltaMillis))
                particle.draw(batch);
            else {
                active[i] = false;
                activeCount--;
            }
        }
    }
    this.activeCount = activeCount;

    if (cleansUpBlendFunction && (additive || premultipliedAlpha))
        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.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.github.fauu.helix.system.ScreenFadingSystem.java

License:Open Source License

@Override
protected void processSystem() {
    if (fadeLevel >= fadeDuration) {
        fadeLevel = fadeDuration;//from  ww w.  j a v  a2s  . c o m
    } else if (fadeLevel <= 0) {
        fadeLevel = 0;
    }

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

    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.setColor(0, 0, 0, fadeLevel / fadeDuration);
    shapeRenderer.rect(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    shapeRenderer.end();

    Gdx.gl.glDisable(GL20.GL_BLEND);

    switch (fadeType) {
    case FADE_OUT:
        fadeLevel += Gdx.graphics.getDeltaTime();
        break;
    case FADE_IN:
        fadeLevel -= Gdx.graphics.getDeltaTime();
        break;
    default:
        throw new IllegalStateException();
    }
}

From source file:com.holotrash.lazerdeath2.lazerdeath2.java

License:Open Source License

@Override
public void render() {
    delta = Gdx.graphics.getDeltaTime();
    Gdx.gl.glClearColor(0, 0, 0, 1);//from   w  ww.  j a  v  a  2 s .  c om
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    if (scrollingUp && camera.position.y < mapData.scrollUpMax) {
        camera.translate(0, SCROLLING_MULTIPLIER * delta);
    }
    if (scrollingDown && camera.position.y > mapData.scrollDownMax) {
        camera.translate(0, (0 - SCROLLING_MULTIPLIER) * delta);
    }
    if (scrollingLeft && camera.position.x > mapData.scrollLeftMax) {
        camera.translate((0 - SCROLLING_MULTIPLIER) * delta, 0);
    }
    if (scrollingRight && camera.position.x < mapData.scrollRightMax) {
        camera.translate(SCROLLING_MULTIPLIER * delta, 0);
    }
    camera.update();
    tiledMapRenderer.setView(camera);
    tiledMapRenderer.render();
    tiledMapRenderer.getBatch().setProjectionMatrix(camera.combined);

    for (Enemy enemy : enemies) {
        if ((selectedUnit == null || !enemy.name().equals(selectedUnit.name()))
                && enemy.position().equals(lastClickedCell)) {
            selectedUnit = enemy;
            System.out.println("selectedUnit equals enemy: " + enemy.name());
        }

    }

    for (Dude dude : dudes) {
        if ((selectedUnit == null || !dude.name().equals(selectedUnit.name()))
                && dude.position().equals(lastClickedCell)) {
            selectedUnit = dude;
            System.out.println("selectedUnit equals dude: " + dude.name());
        }
    }

    //change states of sprites based on dude/enemy flags here
    for (int i = 0; i < dudes.size(); i++) {
        if (!this.playerAttacking && dudes.get(i).position().equals(lastClickedCell) && gm.dudesTurn()) {
            makeRangeHighlight(dudes.get(i));
        }
    }
    for (int i = 0; i < enemies.size(); i++) {
        if (!this.playerAttacking && enemies.get(i).position().equals(lastClickedCell) && gm.dudesTurn()) {
            makeRangeHighlight(enemies.get(i));
        }
    }

    spriteBatch.begin();

    //draw interacted tiles
    for (InteractedTile it : interactedTiles) {
        spriteBatch.draw(it.sprite, 128 * it.position.x(), 128 * it.position.y());
    }
    //draw items

    for (Coord coord : gm.itemWrangler.items.keySet()) {
        tempItem = gm.itemWrangler.items.get(coord);
        spriteBatch.draw(tempItem.tileSprite(), 128 * coord.x(), 128 * coord.y());
    }

    //draw dudes and enemies
    for (int i = 0; i < dudes.size(); i++) {
        spriteBatch.draw(dudes.get(i).sprite(), 128 * (dudes.get(i).position().x()),
                128 * (dudes.get(i).position().y()));

    }
    for (int i = 0; i < enemies.size(); i++) {
        spriteBatch.draw(enemies.get(i).sprite(), 128 * (enemies.get(i).position().x()),
                128 * (enemies.get(i).position().y()));
    }

    //draw cursor
    if (gm.dudesTurn() && selectedUnit != null) {
        spriteBatch.draw(this.unitCursor, 128 * selectedUnit.position().x(), 128 * selectedUnit.position().y());
    }

    if (gm.dudesTurn()) {
        //spriteBatch.setColor(hlColor);
        for (Coord c : highlightTiles.keySet()) {
            spriteBatch.setColor(highlightTiles.get(c).color);
            spriteBatch.draw(highlightTiles.get(c).sprite, 128 * highlightTiles.get(c).position.x(),
                    128 * highlightTiles.get(c).position.y());
        }
        spriteBatch.setColor(Color.WHITE);
    }

    // get a screen-relative point of reference for drawing ui elements
    tempV3 = new Vector3(0, 768, 0);
    tempV3 = camera.unproject(tempV3);

    // draw left side ui buttons
    spriteBatch.draw(this.endTurnButton, tempV3.x + 10, tempV3.y + 625);
    spriteBatch.draw(this.attackButton, tempV3.x + 10, tempV3.y + 500);
    spriteBatch.draw(this.menuButton, tempV3.x + 10, tempV3.y + 375);
    spriteBatch.draw(this.exitGameButton, tempV3.x + 10, tempV3.y + 250);

    // draw left status dialog stuff
    if (this.selectedUnit != null) {
        this.glamourShot = selectedUnit.glamourShot();
        this.currentUnitStats = selectedUnit.toStringz();
        // change left status box text to relevant unit stats:

    }

    spriteBatch.draw(this.leftStatusBox, tempV3.x, tempV3.y);
    spriteBatch.draw(this.rightStatusBox, tempV3.x + 768, tempV3.y - 64);
    spriteBatch.draw(this.glamourShot, tempV3.x, tempV3.y);
    uiFont.setColor(Color.BLACK);
    for (int i = 0; i < 5; i++) {
        if (currentUnitStats.size() > i)
            uiFont.draw(spriteBatch, currentUnitStats.get(i), tempV3.x + 266, tempV3.y + 182 - (i * 32));
    }

    //draw right side ui status console text
    consoleIterator = uiConsole.iterator();
    for (int i = 0; i < 5; i++) {
        if (consoleIterator.hasNext())
            uiFont.draw(spriteBatch, consoleIterator.next(), tempV3.x + 832, tempV3.y + 32 + (i * 32));
    }
    //draw right side ui status console fade out
    spriteBatch.draw(this.rightStatusBoxFade, tempV3.x + 768, tempV3.y - 64);

    if (dialogBox.enabled()) {
        // draw dialog box
        tempV3 = new Vector3(286, 700, 0);
        tempV3 = camera.unproject(tempV3);
        spriteBatch.draw(dialogBox.background(), tempV3.x, tempV3.y);
        tempV3 = new Vector3(384, 635, 0);
        tempV3 = camera.unproject(tempV3);
        spriteBatch.draw(dialogBox.button(), tempV3.x, tempV3.y);
        tempV3 = new Vector3(725, 635, 0);
        tempV3 = camera.unproject(tempV3);
        spriteBatch.draw(dialogBox.button(), tempV3.x, tempV3.y);
        // draw dialog text
        int numLines = dialogBox.currentMessage().size();
        if (numLines > 6)
            numLines = 6;
        tempV3 = new Vector3(384, 150, 0);
        tempV3 = camera.unproject(tempV3);
        for (int i = 0; i < numLines; i++) {
            //dialogFont.draw(spriteBatch, dialogLines.get(i), 384, 625 - (i*50));
            dialogFont.draw(spriteBatch, dialogBox.currentMessage().get(i), tempV3.x, tempV3.y - (i * 50));
        }
        tempV3 = new Vector3(565, 540, 0);
        tempV3 = camera.unproject(tempV3);
        temp = dialogBox.btn1();
        layout.setText(dialogFont, temp);
        dialogFont.draw(spriteBatch, temp, tempV3.x - layout.width, tempV3.y - layout.height);
        tempV3 = new Vector3(965, 540, 0);
        tempV3 = camera.unproject(tempV3);
        temp = dialogBox.btn2();
        layout.setText(dialogFont, temp);
        dialogFont.draw(spriteBatch, temp, tempV3.x - layout.width, tempV3.y - layout.height);
    } else if (this.menuDialog.enabled()) {
        // show menuDialog
        this.screenOrigin = new Vector3(0, 768, 0);
        this.screenOrigin = camera.unproject(this.screenOrigin);
        spriteBatch.draw(menuDialog.background(), screenOrigin.x + 384, screenOrigin.y + 64);
        spriteBatch.draw(menuDialog.buttons(), screenOrigin.x + 384, screenOrigin.y + 64);
        spriteBatch.draw(menuDialog.tabArrows(), screenOrigin.x + 384, screenOrigin.y + 64);
        // show menuDialog components
        for (MenuComponent mc : menuDialog.menuComponents()) {
            if (!Coord.coordsEqual(mc.position, GameMaster.nullCoord)) {
                spriteBatch.draw(mc.sprite, screenOrigin.x + mc.position.x(), screenOrigin.y + mc.position.y());
            }
        }
        // show menu labels
        for (MenuLabel ml : menuDialog.menuLabels()) {
            if (!Coord.coordsEqual(ml.position, GameMaster.nullCoord)) {
                dialogFont.draw(spriteBatch, ml.text, screenOrigin.x + ml.position.x(),
                        screenOrigin.y + ml.position.y());
            }
        }

    } else if (this.ynDialog.enabled()) {
        //show ynDialog
        if (!ynDialog.resultRecorded()) {
            this.screenOrigin = new Vector3(0, 768, 0);
            this.screenOrigin = camera.unproject(this.screenOrigin);
            spriteBatch.draw(ynDialog.background(), screenOrigin.x + 500, screenOrigin.y + 300);
            spriteBatch.draw(ynDialog.buttons(), screenOrigin.x + 500, screenOrigin.y + 300);
            dialogFont.draw(spriteBatch, ynDialog.line1(), screenOrigin.x + 535, screenOrigin.y + 525);
            dialogFont.draw(spriteBatch, ynDialog.line2(), screenOrigin.x + 535, screenOrigin.y + 490);
            dialogFont.draw(spriteBatch, ynDialog.line3(), screenOrigin.x + 535, screenOrigin.y + 455);
            dialogFont.draw(spriteBatch, ynDialog.choice1(), screenOrigin.x + 600, screenOrigin.y + 380);
            dialogFont.draw(spriteBatch, ynDialog.choice2(), screenOrigin.x + 850, screenOrigin.y + 380);
        } else {
            if (this.ynDialog.type() == BooleanDialogType.EXIT_GAME) {
                if (ynDialog.result()) {
                    Gdx.app.exit();
                } else {
                    ynDialog.disable();
                }
            }
        }
    } else {

        //Text overlay? dudes turn? enemies turn?
        tempV3 = new Vector3(0, 768, 0);
        tempV3 = camera.unproject(tempV3);
        if (gm.dudesTurn() && this.overlayFadeCounter > 0) {
            spriteBatch.draw(this.dudesTurnSprite, tempV3.x + 350, tempV3.y + 275);
            overlayFadeCounter--;
        } else if (gm.enemiesTurn() && this.overlayFadeCounter > 0) {
            spriteBatch.draw(this.enemiesTurnSprite, tempV3.x + 350, tempV3.y + 275);
            overlayFadeCounter--;
        }

    }
    spriteBatch.end();
    if (!dialogBox.enabled()) {
        gm.clockTick();
        gm.advanceGame();
    }

}

From source file:com.jlabarca.kflame.MeshShader.java

License:Apache License

@Override
public void render() {
    angle += Gdx.graphics.getDeltaTime() * 45;
    matrix.setToRotation(axis, angle);//www  .ja  v  a2  s. c om

    Gdx.gl20.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    Gdx.gl20.glClearColor(0.2f, 0.2f, 0.2f, 1);
    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.gl20.glEnable(GL20.GL_TEXTURE_2D);
    Gdx.gl20.glEnable(GL20.GL_BLEND);
    Gdx.gl20.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    texture.bind();
    shader.begin();
    shader.setUniformMatrix("u_worldView", matrix);
    shader.setUniformi("u_texture", 0);
    mesh.render(shader, GL20.GL_TRIANGLES);
    shader.end();
}