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.squidpony.the.tsar.TsarGame.java

@Override
public void render() {
    // standard clear the background routine for libGDX
    Gdx.gl.glClearColor(bgColor.r / 255.0f, bgColor.g / 255.0f, bgColor.b / 255.0f, 1.0f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    // not sure if this is always needed...
    Gdx.gl.glEnable(GL20.GL_BLEND);

    // used as the z-axis when generating Simplex noise to make water seem to "move"
    counter += Gdx.graphics.getDeltaTime() * 15;
    // this does the standard lighting for walls, floors, etc. but also uses counter to do the Simplex noise thing.
    lights = DungeonUtility.generateLightnessModifiers(decoDungeon, counter);

    // you done bad. you done real bad.
    if (health <= 0) {
        // still need to display the map, then write over it with a message.
        putMap();/*from   www  .  jav  a2  s .c  om*/
        display.putBoxedString(width / 2 - 18, height / 2 - 10, "   THE TSAR WILL HAVE YOUR HEAD!    ");
        display.putBoxedString(width / 2 - 18, height / 2 - 5, "      AS THE OLD SAYING GOES,       ");
        display.putBoxedString(width / 2 - lang.length() / 2, height / 2, lang);
        display.putBoxedString(width / 2 - 18, height / 2 + 5, "             q to quit.             ");

        // because we return early, we still need to draw.
        stage.draw();
        // q still needs to quit.
        if (input.hasNext())
            input.next();
        return;
    }
    // need to display the map every frame, since we clear the screen to avoid artifacts.
    putMap();
    // if the user clicked, we have a list of moves to perform.
    if (!awaitedMoves.isEmpty()) {
        // extremely similar to the block below that also checks if animations are done
        // this doesn't check for input, but instead processes and removes Points from awaitedMoves.
        if (!display.hasActiveAnimations()) {
            ++framesWithoutAnimation;
            if (framesWithoutAnimation >= 3) {
                framesWithoutAnimation = 0;
                switch (phase) {
                case WAIT:
                case MONSTER_ANIM:
                    Coord m = awaitedMoves.remove(0);
                    toCursor.remove(0);
                    move(m.x - player.gridX, m.y - player.gridY);
                    break;
                case PLAYER_ANIM:
                    postMove();
                    break;
                }
            }
        }
    }
    // if we are waiting for the player's input and get input, process it.
    else if (input.hasNext() && !display.hasActiveAnimations() && phase == Phase.WAIT) {
        input.next();
    }
    // if the previous blocks didn't happen, and there are no active animations, then either change the phase
    // (because with no animations running the last phase must have ended), or start a new animation soon.
    else if (!display.hasActiveAnimations()) {
        ++framesWithoutAnimation;
        if (framesWithoutAnimation >= 3) {
            framesWithoutAnimation = 0;
            switch (phase) {
            case WAIT:
                break;
            case MONSTER_ANIM: {
                phase = Phase.WAIT;
            }
                break;
            case PLAYER_ANIM: {
                postMove();

            }
            }
        }
    }
    // if we do have an animation running, then how many frames have passed with no animation needs resetting
    else {
        framesWithoutAnimation = 0;
    }

    // stage has its own batch and must be explicitly told to draw(). this also causes it to act().
    stage.draw();
    if (help == null) {
        // disolay does not draw all AnimatedEntities by default, since FOV often changes how they need to be drawn.
        batch.begin();
        // the player needs to get drawn every frame, of course.
        display.drawActor(batch, 1.0f, player);
        for (AnimatedEntity mon : monsters.keySet()) {
            // monsters are only drawn if within FOV.
            if (fovmap[mon.gridX][mon.gridY] > 0.0) {
                display.drawActor(batch, 1.0f, mon);
            }
        }
        // batch must end if it began.
        batch.end();
    }
    // if using a filter that changes each frame, clear the known relationship between requested and actual colors
    if (changingColors) {
        fgCenter.clearCache();
        bgCenter.clearCache();
    }
}

From source file:com.strategames.ui.helpers.FilledRectangleImage.java

License:Open Source License

@Override
public void draw(Batch batch, float parentAlpha) {
    batch.end();/*from  www  .  jav  a  2  s  .c o  m*/
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    this.shapeRendererColor.a = this.color.a;
    this.shapeRendererColor.r = this.color.r;
    this.shapeRendererColor.g = this.color.g;
    this.shapeRendererColor.b = this.color.b;
    this.shapeRenderer.begin(ShapeType.Filled);
    this.shapeRenderer.rect(getX(), getY(), getWidth(), getHeight());
    this.shapeRenderer.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
}

From source file:com.sturdyhelmetgames.dodgethecars.screen.TransitionScreen.java

License:Apache License

/**
 * Renders fade in transition.// ww w.j  a  v  a2  s  . co  m
 * 
 * @param delta
 *            delta time
 */
protected void renderFadeIn(float delta) {
    // a simple fade in transition
    if (screenTime > -1f && screenTime < 0.99f) {
        transitionColor.set(0f, 0f, 0f, fadeAlpha -= delta);

        Gdx.gl.glEnable(GL20.GL_BLEND);
        renderer.begin(ShapeType.FilledRectangle);
        renderer.filledRect(0f, 0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), transitionColor,
                transitionColor, transitionColor, transitionColor);
        renderer.end();
        Gdx.gl.glDisable(GL20.GL_BLEND);
    }
}

From source file:com.sturdyhelmetgames.dodgethecars.screen.TransitionScreen.java

License:Apache License

/**
 * Renders fade out transition.//from   w w  w  . ja v a2 s .c  om
 * 
 * @param delta
 *            delta time
 */
protected void renderFadeOut(float delta) {
    if (screenTime > FADE_OUT_START_TIME) {
        transitionColor.set(0f, 0f, 0f, fadeAlpha += delta);

        Gdx.gl.glEnable(GL20.GL_BLEND);
        renderer.begin(ShapeType.FilledRectangle);
        renderer.filledRect(0f, 0f, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), transitionColor,
                transitionColor, transitionColor, transitionColor);
        renderer.end();
        Gdx.gl.glDisable(GL20.GL_BLEND);
    }
}

From source file:com.torrosoft.sopistan.SopistanMain.java

License:Open Source License

@Override
public void render() {

    if (istate == 5)
        return;/*from w  w  w.  j  a  v  a 2  s.c  o  m*/

    batch.begin();

    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    cam.update();
    batch.setProjectionMatrix(cam.combined);

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

    // the end cap scale
    tris.setEndCap(5F);

    // the thickness of the line
    tris.setThickness(30F);

    // generate the triangle strip from our path
    tris.update(swipe.getPath());

    // the vertex color for tinting, i.e. for opacity
    tris.setColor(Color.RED);

    // render the triangles to the screen
    tris.draw(cam);

    int idx = 0;
    for (int y = 0; y < Position.MAX_Y; y++) {
        for (int x = 0; x < Position.MAX_X; x++) {
            ((Sprite) group_sprites.get(idx)).draw(batch);
            idx++;
        }
    }

    // uncomment to see debug lines
    //drawDebug();
    batch.end();

    istate = 1;
}

From source file:com.uwsoft.editor.gdx.ui.components.ItemPhysicsEditor.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    //super.draw(batch, parentAlpha);

    if (isTransform())
        applyTransform(batch, computeTransform());
    Rectangle calculatedScissorBounds = Pools.obtain(Rectangle.class);
    getStage().calculateScissors(new Rectangle(0, 0, getWidth(), getHeight()), calculatedScissorBounds);
    // Enable scissors.
    if (ScissorStack.pushScissors(calculatedScissorBounds)) {
        drawChildren(batch, parentAlpha);
        ScissorStack.popScissors();/*from   w w  w  .j  ava  2  s  .c o m*/
        if (isTransform())
            resetTransform(batch);
    }

    batch.end();

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

    shapeRenderer.setProjectionMatrix(stage.getCamera().combined);
    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
    Gdx.gl.glScissor((int) calculatedScissorBounds.x, (int) calculatedScissorBounds.y, (int) getWidth(),
            (int) getHeight());
    Pools.free(calculatedScissorBounds);
    if (currentMode == EditMode.Create) {
        drawOutlines();
        drawPoints();
        drawNextLine();
    }
    if (currentMode == EditMode.Edit) {
        drawPolygon();
        drawOutlines();
        drawPoints();

    }
    Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
    Gdx.gl.glDisable(GL20.GL_BLEND);
    if (currentMode == EditMode.Test) {
        box2dRenderer.render(physicsEditorWorld, stage.getCamera().combined.scl(1 / PhysicsBodyLoader.SCALE));
    }
    batch.begin();
}

From source file:com.vlaaad.dice.ui.components.Rain.java

License:Open Source License

@Override
public void draw(Batch batch, float parentAlpha) {
    validate();//w ww  . jav  a  2 s . co  m
    batch.end();
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    ShapeRenderer renderer = Config.shapeRenderer;
    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());

    renderer.begin(ShapeRenderer.ShapeType.Filled);
    renderer.setColor(style.color.r, style.color.g, style.color.b, style.color.a * parentAlpha);
    float usedWidth = getWidth() - style.pad;
    int count = (int) (usedWidth / (style.dropWidth + style.pad));
    if (count == 0)
        return;
    float step = usedWidth / ((float) count);
    float x = style.pad;
    for (int i = 0, n = rows.size; i < n; i++) {
        Row row = rows.get(i);
        drawRow(x, row);
        x += step;
    }
    renderer.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
}

From source file:com.watabou.noosa.Game.java

License:Open Source License

public void onSurfaceCreated() {
    Gdx.gl.glEnable(GL20.GL_BLEND);
    // For premultiplied alpha:
    // Gdx.gl.glBlendFunc( GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA );
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);

    TextureCache.reload();//  w  w  w .j  a v a  2 s  .  c  o  m
}

From source file:com.wilson.game.Screen.HelpScreen2.java

License:Apache License

public void draw() {
    GL20 gl = Gdx.gl;//from  w w  w.ja v  a2  s .  co  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, 320, 480);
    game.batcher.end();

    game.batcher.enableBlending();
    game.batcher.begin();
    game.batcher.draw(Assets.arrow, 320, 0, -30, 30);
    game.batcher.end();

    gl.glDisable(GL20.GL_BLEND);
}

From source file:de.caffeineaddicted.sgl.ui.screens.SGLStagedScreen.java

License:BEER-WARE LICENSE

@Override
protected final void draw() {
    onBeforeDraw();/*  www.j  a  v a2 s. c om*/
    if (dimBackground) {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        SGL.provide(ShapeRenderer.class).begin(ShapeRenderer.ShapeType.Filled);
        SGL.provide(ShapeRenderer.class).setColor(0f, 0f, 0f, Math.min(1f, Math.max(0f, dimFactor)));
        SGL.provide(ShapeRenderer.class).rect(stage.getViewOrigX(), stage.getViewOrigY(), stage.getWidth(),
                stage.getHeight());
        SGL.provide(ShapeRenderer.class).end();
        Gdx.gl.glDisable(GL20.GL_BLEND);
    }
    stage.draw();
    onAfterDraw();
}