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:br.com.animvs.koalory.entities.engine.graphics.tiles.TileRenderer.java

License:Apache License

@Override
public void render() {
    if (!cached) {
        cached = true;//  w  ww.  ja v a2  s  . c o  m
        count = 0;
        spriteCache.clear();

        final float extraWidth = viewBounds.width * overCache;
        final float extraHeight = viewBounds.height * overCache;
        cacheBounds.x = viewBounds.x - extraWidth;
        cacheBounds.y = viewBounds.y - extraHeight;
        cacheBounds.width = viewBounds.width + extraWidth * 2;
        cacheBounds.height = viewBounds.height + extraHeight * 2;

        for (MapLayer layer : map.getLayers()) {
            spriteCache.beginCache();
            if (layer instanceof TiledMapTileLayer) {
                renderTileLayer((TiledMapTileLayer) layer);
            }
            spriteCache.endCache();
        }
    }

    if (blending) {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    spriteCache.setShader(controller.getShaderColor().getGDXShader());
    spriteCache.begin();
    controller.getShaderColor().update();

    MapLayers mapLayers = map.getLayers();
    for (int i = 0, j = mapLayers.getCount(); i < j; i++) {
        MapLayer layer = mapLayers.get(i);
        if (layer.isVisible()) {
            spriteCache.draw(i);
            renderObjects(layer);
        }
    }
    spriteCache.end();
    if (blending)
        Gdx.gl.glDisable(GL20.GL_BLEND);
}

From source file:br.com.animvs.koalory.entities.engine.graphics.tiles.TileRenderer.java

License:Apache License

@Override
public void render(int[] layers) {
    if (!cached) {
        cached = true;/*from   ww  w.  j a va2  s  . c om*/
        count = 0;
        spriteCache.clear();

        final float extraWidth = viewBounds.width * overCache;
        final float extraHeight = viewBounds.height * overCache;
        cacheBounds.x = viewBounds.x - extraWidth;
        cacheBounds.y = viewBounds.y - extraHeight;
        cacheBounds.width = viewBounds.width + extraWidth * 2;
        cacheBounds.height = viewBounds.height + extraHeight * 2;

        for (MapLayer layer : map.getLayers()) {
            spriteCache.beginCache();
            if (layer instanceof TiledMapTileLayer) {
                renderTileLayer((TiledMapTileLayer) layer);
            }
            spriteCache.endCache();
        }
    }

    if (blending) {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }
    spriteCache.begin();
    MapLayers mapLayers = map.getLayers();
    for (int i : layers) {
        MapLayer layer = mapLayers.get(i);
        if (layer.isVisible()) {
            spriteCache.draw(i);
            renderObjects(layer);
        }
    }
    spriteCache.end();
    if (blending)
        Gdx.gl.glDisable(GL20.GL_BLEND);
}

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.FadeRenderer.java

License:Apache License

public void shows(float delta) {
    if (!isPlaying)
        return;//w w w  . ja va  2  s  . c  om

    if (isRunning) {
        alpha += ALPHA_VELOCITY * delta;
        if (alpha > 1f) {
            alpha = 1f;
            if (isRunning && onFinished != null) {
                Timer.schedule(new Timer.Task() {
                    @Override
                    public void run() {
                        onFinished.run();
                    }
                }, DELAY_TO_FINISH);
                isRunning = false;
            }
        }
        red = 1f - alpha;
    }

    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    begin(ShapeType.Filled);
    setColor(red, 0f, 0f, alpha);
    rect(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
}

From source file:broken.shotgun.throwthemoon.stages.GameStage.java

License:Open Source License

@Override
public void draw() {
    super.draw();

    if (boss != null) {
        renderer.begin();//from   w ww.j  av  a 2s. c  o m
        moonImpactMeter.draw(renderer);
        renderer.end();
    }

    if (isStageClear()) {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        renderer.begin(ShapeType.Filled);
        renderer.setColor(screenFadeActor.getColor());
        renderer.rect(screenFadeActor.getX(), screenFadeActor.getY(), screenFadeActor.getWidth(),
                screenFadeActor.getHeight());
        renderer.end();
        Gdx.gl.glDisable(GL20.GL_BLEND);
    }

    if (debug) {
        uiBatch.begin();
        font.draw(uiBatch, screenLogger.toString(), 50, 300);
        screenLogger.setLength(0);
        uiBatch.end();
    }
}

From source file:cocos2d.layers_scenes_transitions_nodes.CCLayerColor.java

License:Open Source License

@Override
public void draw() {
    CCDrawManager.SPRITE_BATCH.end();/*from  ww w.  j  av 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);

    CCDrawManager.SHAPE_RENDERER.setProjectionMatrix(CCDrawManager.SPRITE_BATCH.getProjectionMatrix());
    CCDrawManager.SHAPE_RENDERER.setTransformMatrix(CCDrawManager.SPRITE_BATCH.getTransformMatrix());
    CCDrawManager.SHAPE_RENDERER.setColor(_displayedColor.R / 255.0f, _displayedColor.G / 255.0f,
            _displayedColor.B / 255.0f, _displayedOpacity / 255.0f);
    CCDrawManager.SHAPE_RENDERER.begin(ShapeType.Filled);
    CCDrawManager.SHAPE_RENDERER.rect(0, 0, m_obContentSize.width, m_obContentSize.height);
    CCDrawManager.SHAPE_RENDERER.end();

    Gdx.gl.glDisable(GL20.GL_BLEND);

    CCDrawManager.SPRITE_BATCH.begin();
}

From source file:color.guard.GameplayScreen.java

License:Open Source License

@Override
public void show() {
    guiRandom = new RNG(new Lathe32RNG(0x1337BEEFFEEDL));
    Gdx.gl.glDisable(GL20.GL_BLEND);
    viewport = new PixelPerfectViewport(Scaling.fill, visualWidth, visualHeight);
    //viewport = new ScreenViewport();
    //tempVector3 = new Vector3();
    viewport.getCamera().update();/*from ww  w. j a v  a2 s  .c  o m*/
    //prevCameraPosition = viewport.getCamera().position.cpy();
    nextCameraPosition = viewport.getCamera().position.cpy();
    atlas = new TextureAtlas("Iso_Mini.atlas");
    palettes = new Texture("palettes.png");
    tempSB = new StringBuilder(16);

    font = new BitmapFont(Gdx.files.internal("NanoOKExtended.fnt"), atlas.findRegion("NanoOKExtended"));
    //font.getData().setScale(2f);
    font.setColor(1f / 255f, 1f, 1f, 1f);
    //displayString = state.world.mapGen.atlas.getAt(0);
    String s, r;
    terrains = new TextureAtlas.AtlasRegion[WorldState.terrains.length << 2];
    for (int i = 0; i < terrains.length >> 2; i++) {
        terrains[i * 4] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face0", 0);
        terrains[i * 4 + 1] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face1", 0);
        terrains[i * 4 + 2] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face2", 0);
        terrains[i * 4 + 3] = atlas.findRegion(WorldState.terrains[i] + "_Huge_face3", 0);
    }
    ;
    int pieceCount = PieceKind.kinds.size(), facilityCount = PieceKind.facilities.size(),
            totalCount = pieceCount + facilityCount << 2;
    PieceKind p;
    standing = new Animation[totalCount];
    acting0 = new Animation[totalCount];
    acting1 = new Animation[totalCount];
    dying = new Animation[totalCount];
    receiving0 = new Animation[totalCount];
    receiving1 = new Animation[totalCount];
    for (int i = 0; i < pieceCount; i++) {
        p = PieceKind.kinds.getAt(i);
        s = p.visual + "_Large_face";
        standing[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0), Animation.PlayMode.LOOP);
        standing[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1), Animation.PlayMode.LOOP);
        standing[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2), Animation.PlayMode.LOOP);
        standing[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3), Animation.PlayMode.LOOP);
        s = p.visual + "_Large_face";
        if ((p.weapons & 2) != 0) {
            acting0[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_attack_0"));
            acting0[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_attack_0"));
            acting0[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_attack_0"));
            acting0[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_attack_0"));
            r = p.show[0] + "_face";
            receiving0[i << 2] = new Animation<>(0.10f,
                    atlas.createSprites(r + 0 + "_strength_" + p.shownStrengths[0]));
            receiving0[i << 2 | 1] = new Animation<>(0.10f,
                    atlas.createSprites(r + 1 + "_strength_" + p.shownStrengths[0]));
            receiving0[i << 2 | 2] = new Animation<>(0.10f,
                    atlas.createSprites(r + 2 + "_strength_" + p.shownStrengths[0]));
            receiving0[i << 2 | 3] = new Animation<>(0.10f,
                    atlas.createSprites(r + 3 + "_strength_" + p.shownStrengths[0]));
        }
        if ((p.weapons & 1) != 0) {
            acting1[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_attack_1"));
            acting1[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_attack_1"));
            acting1[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_attack_1"));
            acting1[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_attack_1"));
            r = p.show[1] + "_face";
            receiving1[i << 2] = new Animation<>(0.10f,
                    atlas.createSprites(r + 0 + "_strength_" + p.shownStrengths[1]));
            receiving1[i << 2 | 1] = new Animation<>(0.10f,
                    atlas.createSprites(r + 1 + "_strength_" + p.shownStrengths[1]));
            receiving1[i << 2 | 2] = new Animation<>(0.10f,
                    atlas.createSprites(r + 2 + "_strength_" + p.shownStrengths[1]));
            receiving1[i << 2 | 3] = new Animation<>(0.10f,
                    atlas.createSprites(r + 3 + "_strength_" + p.shownStrengths[1]));
        }
        dying[i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_death"));
        dying[i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_death"));
        dying[i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_death"));
        dying[i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_death"));
    }
    for (int i = 0; i < facilityCount; i++) {
        p = PieceKind.facilities.getAt(i);
        s = p.visual + "_Large_face";
        standing[pieceCount + i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0),
                Animation.PlayMode.LOOP);
        standing[pieceCount + i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1),
                Animation.PlayMode.LOOP);
        standing[pieceCount + i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2),
                Animation.PlayMode.LOOP);
        standing[pieceCount + i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3),
                Animation.PlayMode.LOOP);
        s = p.visual + "_Large_face";
        dying[pieceCount + i << 2] = new Animation<>(0.10f, atlas.createSprites(s + 0 + "_death"));
        dying[pieceCount + i << 2 | 1] = new Animation<>(0.10f, atlas.createSprites(s + 1 + "_death"));
        dying[pieceCount + i << 2 | 2] = new Animation<>(0.10f, atlas.createSprites(s + 2 + "_death"));
        dying[pieceCount + i << 2 | 3] = new Animation<>(0.10f, atlas.createSprites(s + 3 + "_death"));
    }
    glp = new GLProfiler(Gdx.graphics);
    glp.enable();
    state.world.startBattle(state.world.factions);
    state.world.battle.resistanceMaps();
    final Coord playerPos = state.world.battle.pieces.firstKey();
    targetCell = playerPos;
    playerPiece = state.world.battle.pieces.getAt(0);
    dijkstra = new DijkstraMap(ArrayTools.fill('.', mapWidth, mapHeight), DijkstraMap.Measurement.MANHATTAN,
            new StatefulRNG(new Lathe32RNG(123456789, 987654321)));
    dijkstra.initializeCost(state.world.battle.resistances[playerPiece.pieceKind.mobility]);
    viewport.getCamera().position.set(32 * (playerPos.y - playerPos.x) + 9f,
            16 * (playerPos.y + playerPos.x) + 13f, 0f);
    viewport.getCamera().update();
    //prevCameraPosition = viewport.getCamera().position.cpy();
    nextCameraPosition = viewport.getCamera().position.cpy();

    //fog = new Noise.Layered3D(SeededNoise.instance, 2, 0.015);

    /*pieces = new int[mapWidth][mapHeight];
    int[] tempOrdering = new int[pieceCount];
    for (int x = mapWidth - 1; x >= 0; x--) {
    CELL_WISE:
    for (int y = mapHeight - 1; y >= 0; y--) {
        if(guiRandom.next(4) == 0) {
            guiRandom.randomOrdering(pieceCount, tempOrdering);
            for (int i = 0; i < pieceCount; i++) {
                if(PieceKind.kinds.getAt(tempOrdering[i]).mobilities[map[x][y]] < 6)
                {
                    pieces[x][y] = tempOrdering[i] << 2 | guiRandom.next(2);
                    continue CELL_WISE;
                }
            }
        }
        pieces[x][y] = -1;
    }
    }
    */
    String vertex = "attribute vec4 a_position;\n" + "attribute vec4 a_color;\n"
            + "attribute vec2 a_texCoord0;\n" + "uniform mat4 u_projTrans;\n" + "varying vec4 v_color;\n"
            + "varying vec2 v_texCoords;\n" + "void main()\n" + "{\n" + "v_color = "
            + ShaderProgram.COLOR_ATTRIBUTE + ";\n" + "v_color.a = v_color.a * (255.0/254.0);\n" + //* (256.0/255.0)
            "v_texCoords = " + ShaderProgram.TEXCOORD_ATTRIBUTE + "0;\n" + "gl_Position = u_projTrans * "
            + ShaderProgram.POSITION_ATTRIBUTE + ";\n" + "}\n";
    String fragment = "#ifdef GL_ES\n" + "#define LOWP lowp\n" + "precision mediump float;\n" + "#else\n"
            + "#define LOWP\n" + "#endif\n" + "varying LOWP vec4 v_color;\n" + "varying vec2 v_texCoords;\n"
            + "uniform sampler2D u_texture;\n" + "uniform sampler2D u_texPalette;\n" + "void main()\n" + "{\n"
            + "vec4 color = texture2D(u_texture, v_texCoords);\n"
            + "vec2 index = vec2(color.r * 255.0 / 255.5, v_color.r);\n"
            + "gl_FragColor = vec4(texture2D(u_texPalette, index).rgb, color.a);\n" + "}\n";
    //        String fragment =
    //                "#ifdef GL_ES\n" +
    //                "#define LOWP lowp\n" +
    //                "precision mediump float;\n" +
    //                "#else\n" +
    //                "#define LOWP\n" +
    //                "#endif\n" +
    //                "varying LOWP vec4 v_color;\n" +
    //                "varying vec2 v_texCoords;\n" +
    //                "uniform sampler2D u_texture;\n" +
    //                "uniform sampler2D u_texPalette;\n" +
    //                "// The MIT License\n" +
    //                "// Copyright  2013 Inigo Quilez\n" +
    //                "// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n" +
    //                "// Gradient Noise 3D             : https://www.shadertoy.com/view/Xsl3Dl\n" +
    //                "//===============================================================================================\n" +
    //                "vec3 hash( vec3 p ) // replace this by something better\n" +
    //                "{\n" +
    //                "    p = vec3( dot(p,vec3(127.1,311.7, 74.7)),\n" +
    //                "        dot(p,vec3(269.5,183.3,246.1)),\n" +
    //                "        dot(p,vec3(113.5,271.9,124.6)));\n" +
    //                "    return -1.0 + 2.0*fract(sin(p)*43758.5453123);\n" +
    //                "}\n" +
    //                "float noise(vec3 p)\n" +
    //                "{\n" +
    //                "    vec3 i = floor(p);\n" +
    //                "    vec3 f = fract(p);\n" +
    //                "    vec3 u = f*f*(3.0-2.0*f);\n" +
    //                "    return " +
    //                        "   mix( mix( mix( dot( hash( i + vec3(0.0,0.0,0.0) ), f - vec3(0.0,0.0,0.0) ), \n" +
    //                "                          dot( hash( i + vec3(1.0,0.0,0.0) ), f - vec3(1.0,0.0,0.0) ), u.x),\n" +
    //                "                     mix( dot( hash( i + vec3(0.0,1.0,0.0) ), f - vec3(0.0,1.0,0.0) ), \n" +
    //                "                          dot( hash( i + vec3(1.0,1.0,0.0) ), f - vec3(1.0,1.0,0.0) ), u.x), u.y),\n" +
    //                "                mix( mix( dot( hash( i + vec3(0.0,0.0,1.0) ), f - vec3(0.0,0.0,1.0) ), \n" +
    //                "                          dot( hash( i + vec3(1.0,0.0,1.0) ), f - vec3(1.0,0.0,1.0) ), u.x),\n" +
    //                "                     mix( dot( hash( i + vec3(0.0,1.0,1.0) ), f - vec3(0.0,1.0,1.0) ), \n" +
    //                "                          dot( hash( i + vec3(1.0,1.0,1.0) ), f - vec3(1.0,1.0,1.0) ), u.x), u.y), u.z)" +
    //                        ";\n" +
    //                "}\n" +
    //                "const mat3 m = mat3( 0.00,  0.80,  0.60,\n" +
    //                "                    -0.80,  0.36, -0.48,\n" +
    //                "                    -0.60, -0.48,  0.64 );\n"+
    //                "// End of MIT-licensed code\n"+
    //                //Jim Hejl and Richard Burgess-Dawson's tone mapping formula
    //                "vec3 tone(vec3 texColor, LOWP float change)\n" +
    //                "{\n" +
    //                "vec3 x = clamp((texColor * 0.666) - 0.004, 0.0, 100.0);\n" +
    //                "return mix(texColor, (x*(6.2*x+.5))/(x*(6.2*x+1.7)+0.06), change);\n" +
    //                "}\n" +
    //                "void main()\n" +
    //                "{\n" +
    //                "vec4 color = texture2D(u_texture, v_texCoords);\n" +
    //                "vec2 index = vec2(color.r * 255.0 / 255.5, v_color.r);\n" +
    //                "vec3 q = vec3(0.01125 * gl_FragCoord.xy, v_color.g * 2.75);\n" +
    ////                "float f = 0.5000*noise( q ); q = m*q*2.01;\n" +
    ////                "f      += 0.3125*noise( q ); q = m*q*2.02;\n" +
    ////                "f      += 0.1875*noise( q );\n" +
    ////                "f      += 0.0625*noise( q ); q = m*q*2.01;\n" +
    //                "gl_FragColor = vec4(tone(texture2D(u_texPalette, index).rgb, 0.65 - noise(q) * 0.75), color.a);\n" +
    //                "}\n";
    indexShader = new ShaderProgram(vertex, fragment);
    if (!indexShader.isCompiled())
        throw new GdxRuntimeException("Error compiling shader: " + indexShader.getLog());

    map = ArrayTools.copy(state.world.worldMap);
    for (int x = 0; x < mapWidth; x++) {
        for (int y = 0; y < mapHeight; y++) {
            map[x][y] = map[x][y] * 4 + guiRandom.next(2);
        }
    }
    batch = new SpriteBatch();
    proc = new InputAdapter() {
        @Override
        public boolean touchUp(int screenX, int screenY, int pointer, int button) {
            if (inputMode == INPUT_LOCKED)
                return false;
            inputMode = INPUT_LOCKED;

            nextCameraPosition.set(screenX, screenY, 0);
            viewport.unproject(nextCameraPosition);
            //32 * y - 32 * x, 16 * y + 16 * x
            /*
            nx = 32 * y - 32 * x
            ny = 16 * y + 16 * x
            nx + 2ny = 64y
            nx - 2ny = -64x  
            */
            targetCell = Coord.get(
                    MathUtils.round((nextCameraPosition.x - nextCameraPosition.y * 2f + 32f) / -64f),
                    MathUtils.round((nextCameraPosition.x + nextCameraPosition.y * 2f - 96f) / 64f));
            dijkstra.clearGoals();
            dijkstra.findPath(playerPiece.pieceKind.stats[PieceKind.MOV], 20,
                    state.world.battle.pieces.keySet(), null, state.world.battle.pieces.firstKey(), targetCell);
            return true;
        }

        @Override
        public boolean keyDown(int keycode) {
            if (inputMode == INPUT_LOCKED)
                return false;
            switch (keycode) {
            case Input.Keys.RIGHT:
                lastArrow = Direction.LEFT;
                break;
            case Input.Keys.LEFT:
                lastArrow = Direction.RIGHT;
                break;
            case Input.Keys.UP:
                lastArrow = Direction.DOWN;
                break;
            case Input.Keys.DOWN:
                lastArrow = Direction.UP;
                break;
            //default: lastArrow = Direction.NONE;
            default:
                return false;
            }
            targetCell = playerPos.translate(lastArrow);
            dijkstra.clearGoals();
            dijkstra.findPath(playerPiece.pieceKind.stats[PieceKind.MOV], 20,
                    state.world.battle.pieces.keySet(), null, state.world.battle.pieces.firstKey(), targetCell);
            inputMode = INPUT_LOCKED;
            return true;
        }
    };
    Gdx.input.setInputProcessor(proc);
}

From source file:com.badlogicgames.superjumper.helpscreen.HelpScreen2.java

License:Apache License

public void draw() {
    GL20 gl = Gdx.gl;/*w  ww .ja  v  a2 s  . co m*/
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    guiCam.update();

    game.batch.setProjectionMatrix(guiCam.combined);
    game.batch.disableBlending();
    game.batch.begin();
    game.batch.draw(helpRegion, 0, 0, 320, 480);
    game.batch.end();

    game.batch.enableBlending();
    game.batch.begin();
    game.batch.draw(Assets.arrow, 320, 0, -64, 64);
    game.batch.end();

    gl.glDisable(GL20.GL_BLEND);
}

From source file:com.balloongame.handlers.CustomSpriteBatch.java

License:Apache License

/** <p>
 * Constructs a new SpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards, x-axis
 * point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect with
 * respect to the screen resolution.// www . ja  v a  2 s  .c  om
 * </p>
 * 
 * <p>
 * The size parameter specifies the maximum size of a single batch in number of sprites
 * </p>
 * 
 * <p>
 * The defaultShader specifies the shader to use. Note that the names for uniforms for this default shader are different than
 * the ones expect for shaders set with {@link #setShader(ShaderProgram)}. See the {@link #createDefaultShader()} method.
 * </p>
 * 
 * @param size the batch size in number of sprites
 * @param buffers the number of buffers to use. only makes sense with VBOs. This is an expert function.
 * @param defaultShader the default shader to use. This is not owned by the SpriteBatch and must be disposed separately. */
public CustomSpriteBatch(int size, int buffers, ShaderProgram defaultShader) {
    super(0);
    super.dispose();
    //enable blending
    Gdx.gl.glEnable(GL20.GL_BLEND);
    if (blendSrcFunc != -1)
        Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc);

    this.buffers = new Mesh[buffers];

    for (int i = 0; i < buffers; i++) {
        this.buffers[i] = new Mesh(VertexDataType.VertexArray, false, size * 4, size * 6,
                new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE),
                new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE),
                new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
    }

    projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    vertices = new float[size * SPRITE_SIZE];

    int len = size * 6;
    short[] indices = new short[len];
    short j = 0;
    for (int i = 0; i < len; i += 6, j += 4) {
        indices[i + 0] = (short) (j + 0);
        indices[i + 1] = (short) (j + 1);
        indices[i + 2] = (short) (j + 2);
        indices[i + 3] = (short) (j + 2);
        indices[i + 4] = (short) (j + 3);
        indices[i + 5] = (short) (j + 0);
    }
    for (int i = 0; i < buffers; i++) {
        this.buffers[i].setIndices(indices);
    }
    mesh = this.buffers[0];

    if (Gdx.graphics.isGL20Available() && defaultShader == null) {
        shader = createDefaultShader();
        ownsShader = true;
    } else
        shader = defaultShader;
}

From source file:com.balloongame.handlers.CustomSpriteBatch.java

License:Apache License

private void renderMesh() {
    if (idx == 0)
        return;// www . j  ava  2s .  com

    renderCalls++;
    totalRenderCalls++;
    //int spritesInBatch = idx / 20;
    //if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch;
    int meshIndicesBufferLimit = idx * 6 / 20;

    lastTexture.bind(0);
    mesh.setVertices(vertices, 0, idx);
    mesh.getIndicesBuffer().position(0);
    mesh.getIndicesBuffer().limit(meshIndicesBufferLimit);

    if (blendingDisabled) {
        Gdx.gl.glDisable(GL20.GL_BLEND);
    } else {
        Gdx.gl.glEnable(GL20.GL_BLEND);
        if (blendSrcFunc != -1)
            Gdx.gl.glBlendFunc(blendSrcFunc, blendDstFunc);
    }

    if (Gdx.graphics.isGL20Available()) {
        mesh.render(customShader != null ? customShader : shader, GL10.GL_TRIANGLES, 0, meshIndicesBufferLimit);//mesh.render(shader, GL10.GL_TRIANGLES, 0, meshIndicesBufferLimit);
    } else {
        mesh.render(GL10.GL_TRIANGLES, 0, meshIndicesBufferLimit);
    }

    idx = 0;
    currBufferIdx++;
    if (currBufferIdx == buffers.length)
        currBufferIdx = 0;
    mesh = buffers[currBufferIdx];
}

From source file:com.belocraft.gameworld.GameRenderer.java

private void drawTransition(float delta) {
    if (alpha.getValue() > 0) {
        manager.update(delta);//from  w  w  w. 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);
        shapeRenderer.begin(ShapeType.Filled);
        shapeRenderer.setColor(1, 1, 1, alpha.getValue());
        shapeRenderer.rect(0, 0, 136, 300);
        shapeRenderer.end();
        Gdx.gl.glDisable(GL20.GL_BLEND);

    }
}