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.o2d.pkayjava.editor.view.ui.followers.PolygonFollower.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    if (polygonComponent != null && polygonComponent.vertices != null) {
        batch.end();// w  ww . ja  v  a 2 s. c  om

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

        shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
        Matrix4 matrix = batch.getTransformMatrix();
        matrix.scale(pixelsPerWU / runtimeCamera.zoom, pixelsPerWU / runtimeCamera.zoom, 1f);
        shapeRenderer.setTransformMatrix(matrix);

        drawTriangulatedPolygons();
        drawOutlines();
        drawPoints();

        Gdx.gl.glDisable(GL20.GL_BLEND);

        batch.begin();
    }
}

From source file:com.o2d.pkayjava.editor.view.ui.widget.actors.GridView.java

License:Apache License

@Override
public void draw(Batch batch, float parentAlpha) {
    batch.end();//from  ww w  .j av a  2  s.  c om

    OrthographicCamera uiCamera = (OrthographicCamera) Sandbox.getInstance().getUIStage().getCamera();

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

    shapeRenderer.setProjectionMatrix(uiCamera.projection);

    drawLines();

    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
    batch.setColor(Color.WHITE);

    OrthographicCamera runtimeCamera = Sandbox.getInstance().getCamera();
    batch.setProjectionMatrix(uiCamera.projection);
    zeroLabel.draw(batch, parentAlpha);
    zeroLabel.setX(-(runtimeCamera.position.x * pixelsPerWU) / runtimeCamera.zoom - 5 - zeroLabel.getWidth());
    zeroLabel.setY(-(runtimeCamera.position.y * pixelsPerWU) / runtimeCamera.zoom - zeroLabel.getHeight());
}

From source file:com.perfectplay.org.SkyBox.java

License:Open Source License

public void render(PerspectiveCamera camera) {
    invView.set(camera.view);/*from  ww  w.j  av a  2s . co m*/

    // Remove translation
    invView.val[Matrix4.M03] = 0;
    invView.val[Matrix4.M13] = 0;
    invView.val[Matrix4.M23] = 0;

    invView.inv().tra();

    mvp.set(camera.projection);
    mvp.mul(invView);

    Gdx.gl.glEnable(GL20.GL_CULL_FACE);
    Gdx.gl.glCullFace(GL20.GL_FRONT);
    Gdx.gl.glFrontFace(GL20.GL_CCW);

    Gdx.gl20.glDisable(GL20.GL_BLEND);
    Gdx.gl20.glDisable(GL20.GL_DEPTH_TEST);
    Gdx.gl20.glDepthMask(false);

    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
    Gdx.gl20.glBindTexture(GL20.GL_TEXTURE_CUBE_MAP, g_cubeTexture);

    program.begin();

    program.setUniformMatrix("u_mvpMatrix", mvp);
    program.setUniformi("s_cubemap", 0);

    cube.render(program, GL20.GL_TRIANGLE_STRIP);

    program.end();

    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthMask(true);
}

From source file:com.prisonbreak.game.MapControlRenderer.java

@Override
public void render() {
    if (state == STATE.ONGOING) {
        player.update();/* w ww .j  av a 2  s.c o  m*/
        moveCamera();

        // check if Player is detected by the Guards
        for (Guard guard : guards) {
            if (guard instanceof PatrolGuard) {
                ((PatrolGuard) guard).update();
            }

            if (guard.detectPlayer()) {
                //                    Gdx.app.log("Game over", "");
                loseGame();
                break;
            }
        }

        // search for the door in contact
        for (Object o : doorObjects) {
            RectangleMapObject r = null;
            if (o instanceof RectangleMapObject) {
                r = (RectangleMapObject) o;
            }

            if (r != null && r.getRectangle().overlaps(player.getSprite().getBoundingRectangle())) {
                currentDoor = r;
                break;
            }
        }

        // the door "disappears" when Player steps in
        // and "showed" again when Player steps out
        if (currentDoor != null) {
            int x = currentDoor.getProperties().get("lowerLeftX", Integer.class);
            int y = currentDoor.getProperties().get("lowerLeftY", Integer.class);
            String name = currentDoor.getProperties().get("tileLayerName", String.class);
            TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(name);

            // if the door has not been hidden, and Player steps in -> hide the door
            if (!currentDoor.getProperties().get("locked", Boolean.class) && !doorHidden
                    && currentDoor.getRectangle().overlaps(player.getSprite().getBoundingRectangle())) {
                // extract the tiles
                tile1 = layer.getCell(x, y).getTile(); // lower left
                tile2 = layer.getCell(x + 1, y).getTile(); // lower right
                tile3 = layer.getCell(x, y + 1).getTile(); // upper left
                tile4 = layer.getCell(x + 1, y + 1).getTile(); // upper right

                // "hide" the door when Player steps in
                layer.getCell(x, y).setTile(null);
                layer.getCell(x + 1, y).setTile(null);
                layer.getCell(x, y + 1).setTile(null);
                layer.getCell(x + 1, y + 1).setTile(null);

                doorHidden = true; // set the flag
            }

            // if the door is currently hidden, and Player steps out -> show it
            if (!currentDoor.getProperties().get("locked", Boolean.class) && doorHidden
                    && !currentDoor.getRectangle().overlaps(player.getSprite().getBoundingRectangle())) {
                // "show" the door when Player steps out
                layer.getCell(x, y).setTile(tile1);
                layer.getCell(x + 1, y).setTile(tile2);
                layer.getCell(x, y + 1).setTile(tile3);
                layer.getCell(x + 1, y + 1).setTile(tile4);

                doorHidden = false;
            }
        }

        // update winning state
        if (winGame())
            state = STATE.WIN;
    }

    shapeRenderer.setProjectionMatrix(camera.combined);

    beginRender();

    int currentLayer = 0;
    for (MapLayer layer : map.getLayers()) {
        if (layer.isVisible()) {
            // tile layer
            if (layer instanceof TiledMapTileLayer) {
                renderTileLayer((TiledMapTileLayer) layer);
                ++currentLayer;

                // layer to draw characters and guards
                if (currentLayer == drawSpritesAfterLayer) {
                    // draw player
                    player.getSprite().draw(this.getBatch());

                    // draw all the guards
                    for (Guard guard : guards) {
                        guard.getSprite().draw(this.getBatch());
                    }
                }
                // layer to draw guard's detection area
                // note: even though detection area is RECTANGLE
                //      , draw a POLYGON instead (POLYGON still inside the RECTANGLE)                            
                if (currentLayer == drawDetectionAreaAfterLayer) {
                    for (Guard guard : guards) {
                        endRender();

                        // first, determine the four vertices
                        float nearLeftX, nearLeftY, nearRightX, nearRightY, // "nearer" points in Guard's POV
                                farLeftX, farLeftY, farRightX, farRightY; // "further" points in Guard's POV
                        if (guard.getCurrentDirection().equalsIgnoreCase("up")) {
                            nearLeftX = guard.getDetectArea().x + guard.getDetectArea().width / 4;
                            nearRightX = guard.getDetectArea().x + guard.getDetectArea().width * 3 / 4;
                            nearLeftY = nearRightY = guard.getDetectArea().y;

                            farLeftX = guard.getDetectArea().x;
                            farRightX = guard.getDetectArea().x + guard.getDetectArea().width;
                            farLeftY = farRightY = guard.getDetectArea().y + guard.getDetectArea().height;
                        } else if (guard.getCurrentDirection().equalsIgnoreCase("down")) {
                            nearLeftX = guard.getDetectArea().x + guard.getDetectArea().width * 3 / 4;
                            nearRightX = guard.getDetectArea().x + guard.getDetectArea().width / 4;
                            nearLeftY = nearRightY = guard.getDetectArea().y + guard.getDetectArea().height;

                            farLeftX = guard.getDetectArea().x + guard.getDetectArea().width;
                            farRightX = guard.getDetectArea().x;
                            farLeftY = farRightY = guard.getDetectArea().y;
                        } else if (guard.getCurrentDirection().equalsIgnoreCase("right")) {
                            nearLeftY = guard.getDetectArea().y + guard.getDetectArea().height * 3 / 4;
                            nearRightY = guard.getDetectArea().y + guard.getDetectArea().height / 4;
                            nearLeftX = nearRightX = guard.getDetectArea().x;

                            farLeftY = guard.getDetectArea().y + guard.getDetectArea().height;
                            farRightY = guard.getDetectArea().y;
                            farLeftX = farRightX = guard.getDetectArea().x + guard.getDetectArea().width;
                        } else if (guard.getCurrentDirection().equalsIgnoreCase("left")) {
                            nearLeftY = guard.getDetectArea().y + guard.getDetectArea().height / 4;
                            nearRightY = guard.getDetectArea().y + guard.getDetectArea().height * 3 / 4;
                            nearLeftX = nearRightX = guard.getDetectArea().x + guard.getDetectArea().width;

                            farLeftY = guard.getDetectArea().y;
                            farRightY = guard.getDetectArea().y + guard.getDetectArea().height;
                            farLeftX = farRightX = guard.getDetectArea().x;
                        } else {
                            nearLeftX = nearLeftY = nearRightX = nearRightY = 0;
                            farLeftX = farLeftY = farRightY = farRightX = 0;
                        }

                        // draw detection area
                        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(1, 0, 0, 0.5f);
                        if (guard.getCurrentDirection().equalsIgnoreCase("up")) {
                            // the body (rectangle) of the polygon
                            shapeRenderer.rect(nearLeftX, nearLeftY, nearRightX - nearLeftX,
                                    farLeftY - nearLeftY);

                            // the left side (triangle) of the polygon
                            shapeRenderer.triangle(nearLeftX, nearLeftY, farLeftX, farLeftY, nearLeftX,
                                    farLeftY);

                            // the right side (triangle) of the polygon
                            shapeRenderer.triangle(nearRightX, nearRightY, farRightX, farRightY, nearRightX,
                                    farRightY);
                        } else if (guard.getCurrentDirection().equalsIgnoreCase("down")) {
                            // the body (rectangle) of the polygon
                            shapeRenderer.rect(nearRightX, farRightY, nearLeftX - nearRightX,
                                    nearRightY - farRightY);

                            // the left side (triangle) of the polygon
                            shapeRenderer.triangle(nearLeftX, nearLeftY, farLeftX, farLeftY, nearLeftX,
                                    farLeftY);

                            // the right side (triangle) of the polygon
                            shapeRenderer.triangle(nearRightX, nearRightY, farRightX, farRightY, nearRightX,
                                    farRightY);
                        } else if (guard.getCurrentDirection().equalsIgnoreCase("right")) {
                            // the body (rectangle) of the polygon
                            shapeRenderer.rect(nearRightX, nearRightY, farRightX - nearRightX,
                                    nearLeftY - nearRightY);

                            // the left side (triangle) of the polygon
                            shapeRenderer.triangle(nearLeftX, nearLeftY, farLeftX, farLeftY, farLeftX,
                                    nearLeftY);

                            // the right side (triangle) of the polygon
                            shapeRenderer.triangle(nearRightX, nearRightY, farRightX, farRightY, farRightX,
                                    nearRightY);
                        } else if (guard.getCurrentDirection().equalsIgnoreCase("left")) {
                            // the body (rectangle) of the polygon
                            shapeRenderer.rect(farLeftX, nearLeftY, nearLeftX - farLeftX,
                                    nearRightY - nearLeftY);

                            // the left side (triangle) of the polygon
                            shapeRenderer.triangle(nearLeftX, nearLeftY, farLeftX, farLeftY, farLeftX,
                                    nearLeftY);

                            // the right side (triangle) of the polygon
                            shapeRenderer.triangle(nearRightX, nearRightY, farRightX, farRightY, farRightX,
                                    nearRightY);
                        }

                        shapeRenderer.end();
                        Gdx.gl.glDisable(GL20.GL_BLEND);

                        beginRender();
                    }
                }
            }
            // object layer
            else {
                for (MapObject object : layer.getObjects()) {
                    renderObject(object);
                }
            }
        }
    }

    endRender();

    stage.act();
    stage.draw();
}

From source file:com.ray3k.skincomposer.GradientDrawable.java

License:Open Source License

@Override
public void draw(Batch batch, float x, float y, float width, float height) {
    float[] alphas = { col1.a, col2.a, col3.a, col4.a };
    col1.a = batch.getColor().a * col1.a;
    col2.a = batch.getColor().a * col2.a;
    col3.a = batch.getColor().a * col3.a;
    col4.a = batch.getColor().a * col4.a;

    g.begin(ShapeRenderer.ShapeType.Filled);
    g.setProjectionMatrix(batch.getProjectionMatrix());
    g.setTransformMatrix(batch.getTransformMatrix());
    batch.end();/*from w w  w  . jav a2  s .c  om*/
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    g.rect(x + borderLeft, y + borderBottom, width - borderLeft - borderRight,
            height - borderBottom - borderTop, col1, col2, col3, col4);
    g.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();

    col1.a = alphas[0];
    col2.a = alphas[1];
    col3.a = alphas[2];
    col4.a = alphas[3];
}

From source file:com.retrom.volcano.game.WorldRenderer.java

License:Apache License

private void renderOverlay() {
    if (world.slomoTime <= 0 && world.lava_ == null) {
        return;//  w  w w  .  j  av  a 2s  .co m
    }
    float alpha = Math.min(Math.min(1, world.slomoTime),
            (world.consecutiveSlomo ? 1 : (World.TOTAL_SLOMO_TIME - world.slomoTime)) / 0.25f);
    alpha *= 0.30f;

    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    shapeRenderer.setProjectionMatrix(cam.combined);
    shapeRenderer.begin(ShapeType.Filled);
    if (alpha > 0) {
        shapeRenderer.setColor(1, 0, 1, alpha);
        shapeRenderer.rect(-FRUSTUM_WIDTH / 2, -FRUSTUM_HEIGHT + world.camTarget, FRUSTUM_WIDTH,
                FRUSTUM_HEIGHT * 2);
    }
    shapeRenderer.end();
    return;
}

From source file:com.retrom.volcano.game.WorldRenderer.java

License:Apache License

private void renderLava() {
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    shapeRenderer.setProjectionMatrix(cam.combined);
    shapeRenderer.begin(ShapeType.Filled);
    if (world.lava_ != null) {
        world.lava_.cam_y = cam.position.y;
        world.lava_.render(batch, shapeRenderer);
    }//from   w  w  w  .  j  a v  a  2  s .c  o m
    shapeRenderer.end();
}

From source file:com.retrom.volcano.game.WorldRenderer.java

License:Apache License

private void renderLavaTop() {
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    shapeRenderer.setProjectionMatrix(cam.combined);
    shapeRenderer.begin(ShapeType.Filled);
    if (world.lava_ != null) {
        world.lava_.cam_y = cam.position.y;
        world.lava_.renderTop(batch, shapeRenderer);
    }/*from ww w. j a va  2 s  .  c o m*/
    shapeRenderer.end();
}

From source file:com.retrom.volcano.game.WorldRenderer.java

License:Apache License

private void renderBlackBottomFade() {
    if (world.gameState != World.State.GAME) {
        return;/*w ww  . j  av a2s  .c  o m*/
    }

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

    shapeRenderer.begin(ShapeType.Filled);

    float y = cam.position.y - FRUSTUM_HEIGHT / 2;

    float x_left = -Lava.WIDTH / 2;
    float x_right = Lava.WIDTH / 2;

    Color topColor = new Color(0, 0, 0, 0);
    Color bottomColor = new Color(0, 0, 0, 0.8f * Utils.clamp01(world.gameTime));
    BatchUtils.drawQuad(shapeRenderer, x_left, y, x_right, y, x_right, y + BOTTOM_FADE_HEIGHT / 3, x_left,
            y + BOTTOM_FADE_HEIGHT / 3, bottomColor, bottomColor);
    BatchUtils.drawQuad(shapeRenderer, x_left, y + BOTTOM_FADE_HEIGHT / 3, x_right, y + BOTTOM_FADE_HEIGHT / 3,
            x_right, y + BOTTOM_FADE_HEIGHT, x_left, y + BOTTOM_FADE_HEIGHT, bottomColor, topColor);

    shapeRenderer.end();
}

From source file:com.squidpony.pandora.PandoraGame.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(decoDungeons[currentDepth], 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();//  w  ww  .  java  2s .c  o  m
        display.putBoxedString(width - 20, height / 2 - 10, "PANDORA! PUNCHING WON'T SOLVE ANYTHING!");
        display.putBoxedString(width - 20, height / 2 - 6, "     YOU SHOULD MIX IN EAR-BITING.     ");
        display.putBoxedString(width - 20, height / 2 - 2, " YOU REMEMBER YOUR GRANDMOTHER'S VOICE,");
        display.putBoxedString(width - lang.length() / 2 - 1, height / 2 + 2, "\"" + lang + "\"");
        display.putBoxedString(width - 20, height / 2 + 6, "               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();
    }
}