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

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

Introduction

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

Prototype

int GL_TEXTURE1

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

Click Source Link

Usage

From source file:color.guard.GameplayScreen.java

License:Open Source License

@Override
public void render(float delta) {
    //GLProfiler.reset();
    glp.reset();/*  ww w. j a v a 2 s.  c o  m*/
    Gdx.graphics.setTitle("Color Guard, running at " + Gdx.graphics.getFramesPerSecond() + " FPS");
    currentTime += delta;
    //        float swap = (NumberTools.zigzag(currentTime * 1.141592653589793f)
    //                + NumberTools.zigzag(currentTime * 1.218281828459045f)
    //                + NumberTools.zigzag(currentTime * 0.718281828459045f)
    //                + NumberTools.sway(currentTime * 0.141592653589793f)) * 0.125f + 0.5f;

    //        cameraTraversed = Math.min(1f, cameraTraversed + delta * 8);
    //        tempVector3.set(prevCameraPosition).lerp(nextCameraPosition, cameraTraversed);
    //        viewport.getCamera().position.set(tempVector3);
    if (inputMode == INPUT_LOCKED) {
        if (dijkstra.path.isEmpty())
            inputMode = INPUT_ALLOWED;
        else if ((turnTime += delta) >= 0.75f) {
            turnTime = 0f;
            //dijkstra.path.size() - 1
            Coord pt = state.world.battle.moveTargets.getAt(0), next = dijkstra.path.remove(0);
            //, playerPos = state.world.battle.pieces.keyAt(0);

            Piece p;
            if (state.world.battle.pieces.keyAt(0).equals(pt))
                p = state.world.battle.pieces.getAt(0);
            else
                p = state.world.battle.pieces.alterAtCarefully(0, pt);
            if (p != null) {
                p = state.world.battle.pieces.getAt(0);
                lastArrow = Direction.getRoughDirection(next.x - pt.x, next.y - pt.y);
                p.faceDirection(lastArrow);
                int idx = state.world.battle.moveTargets.indexOf(next);
                if (idx >= 0)
                    state.world.battle.moveTargets.alterAt(idx, state.world.battle.pieces.keyAt(idx));
                if (!state.world.battle.pieces.containsKey(next))
                //&& (p.pieceKind.permits & 1 << map[next.x][next.y]) != 0
                {
                    state.world.battle.moveTargets.alter(pt, next);
                    lastArrow = Direction.NONE;
                }
            }
        }
    } else if ((turnTime += delta) >= 1.5f) {
        turnTime = 0f;
        Coord pt = state.world.battle.moveTargets.getAt(0);
        Piece p;
        if (state.world.battle.pieces.keyAt(0).equals(pt))
            p = state.world.battle.pieces.getAt(0);
        else
            p = state.world.battle.pieces.alterAtCarefully(0, pt);
        if (p != null) {
            p = state.world.battle.pieces.getAt(0);
            p.faceDirection(lastArrow);
            Coord next = pt.translateCapped(lastArrow.deltaX, lastArrow.deltaY, map.length, map[0].length);
            if (!state.world.battle.pieces.containsKey(next) && !state.world.battle.moveTargets.contains(next))
            //                    && (p.pieceKind.permits & 1 << map[next.x][next.y]) != 0)
            {
                state.world.battle.moveTargets.alter(pt, next);
                lastArrow = Direction.NONE;
            }
            state.world.battle.advanceTurn();
        }
    }

    //displayString = state.world.mapGen.atlas.getAt(((int)currentTime >>> 2) % 24 + 2);
    Gdx.gl.glClearColor(0.45F, 0.7F, 1f, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    int currentKind;
    Piece currentPiece;
    Sprite sprite;
    Coord c, n;
    BattleState battle = state.world.battle;
    OrderedMap<Coord, Piece> pieces = battle.pieces;
    float offX, offY;
    int idx;
    c = pieces.keyAt(0);
    n = battle.moveTargets.getAt(0);
    offX = MathUtils.lerp(0f, 32f * ((n.y - c.y) - (n.x - c.x)), Math.min(1f, turnTime * 1.6f));
    offY = MathUtils.lerp(0f, 16f * ((n.y - c.y) + (n.x - c.x)), Math.min(1f, turnTime * 1.6f));
    Vector3 position = viewport.getCamera().position.set(32 * (c.y - c.x) + offX + 9f,
            16 * (c.y + c.x) + offY + 13f, 0f);
    viewport.getCamera().update();

    viewport.apply(false);

    batch.setProjectionMatrix(viewport.getCamera().combined);

    batch.setShader(indexShader);
    Gdx.gl.glActiveTexture(GL20.GL_TEXTURE1);
    palettes.bind();
    batch.begin();

    //indexShader.setUniformi("u_texPalette", 2);
    indexShader.setUniformi("u_texPalette", 1);
    Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
    //textures.first().bind(1);
    //        indexShader.setUniformi("u_texture", 1);

    int centerX = -(int) ((position.x) - 2 * (position.y)) >> 6,
            centerY = (int) ((position.x) + 2 * (position.y)) >> 6, minX = Math.max(0, centerX - 13),
            maxX = Math.min(centerX + 14, mapWidth - 1), minY = Math.max(0, centerY - 14),
            maxY = Math.min(centerY + 13, mapHeight - 1);
    batch.setColor(208f / 255f, 1f, 1f, 1f);
    for (int x = maxX; x >= minX; x--) {
        for (int y = maxY; y >= minY; y--) {
            currentKind = map[x][y];
            //batch.setColor(208f / 255f, MathUtils.clamp((float) fog.getNoise(32 * y - 32 * x, 16 * y + 16 * x, currentTime * 60) * 0.7f + 0.7f, 0.1f, 1f), 1f, 1f);
            batch.draw(terrains[currentKind], 32 * (y - x), 16 * (y + x));
            //                tempSB.setLength(0);
            //                font.draw(batch, tempSB.append(state.world.bioGen.heatCodeData[x][y]),
            //                        32 * y - 32 * x, 16 * y + 16 * x + 32, 64f, 1, false);
        }
    }
    /*int centerX = (int)(position.x) >> 5,
        centerY = (int)(position.y) >> 5,
        minX = Math.max(0, centerX - 13), maxX = Math.min(centerX + 13, mapWidth - 1),
        minY = Math.max(0, centerY - 8), maxY = Math.min(centerY + 8, mapHeight - 1);
    for (int y = maxY; y >= minY; y--) {
    for (int x = maxX; x >= minX; x--) {
        currentKind = map[x][y];
        batch.setColor((208) / 255f, 1f, 1f, 1f);
        batch.draw(terrains[currentKind], 32 * x, 32 * y);
    }
    }
    */
    for (int y = maxY; y >= minY; y--) {
        for (int x = maxX; x >= minX; x--) {
            if ((currentPiece = pieces.get(c = Coord.get(x, y))) != null) {
                idx = pieces.indexOf(c);
                n = battle.moveTargets.getAt(idx);
                currentKind = currentPiece.kind << 2 | currentPiece.facing;
                if (c.equals(n) && idx != 0) {
                    if (inputMode == INPUT_LOCKED) {
                        sprite = (Sprite) standing[currentKind].getKeyFrame(currentTime, true);
                        offX = 0f;
                        offY = 0f;
                    } else {
                        switch (currentPiece.pieceKind.weapons) {
                        case 2:
                            sprite = (Sprite) acting0[currentKind].getKeyFrame(turnTime, false);
                            offX = -40f;
                            offY = -20f;
                            break;
                        case 3:
                            sprite = (Sprite) (((currentKind * (x << 4 | 13) * (y << 4 | 11) & 256) == 0)
                                    ? acting0
                                    : acting1)[currentKind].getKeyFrame(turnTime, false);
                            offX = -40f;
                            offY = -20f;
                            break;
                        case 1:
                            sprite = (Sprite) acting1[currentKind].getKeyFrame(turnTime, false);
                            offX = -40f;
                            offY = -20f;
                            break;
                        default:
                            sprite = (Sprite) standing[currentKind].getKeyFrame(currentTime, true);
                            offX = 0f;
                            offY = 0f;
                            break;
                        }
                    }
                    sprite.setColor(currentPiece.palette, 1f, 1f, 1f);
                    //MathUtils.clamp((float) fog.getNoise(32 * (y - x) + offX + 9f, 16 * (y + x) + offY + 13f, currentTime * 60) * 0.7f + 0.7f, 0.1f, 1f)
                    sprite.setPosition(32 * (y - x) + offX + 9f, 16 * (y + x) + offY + 13f);
                    sprite.draw(batch);

                    batch.setColor(Math.max(1, currentPiece.paint) / 255f, 0, 1, 1);
                    font.draw(batch, currentPiece.stats, 32 * (y - x) + 9f, 16 * (y + x) + 73f, 48f,
                            Align.center, true);
                    //batch.setColor(-0x1.fffffep126f); // white as a packed float
                } else {
                    boolean isPlayer = currentPiece.equals(playerPiece);
                    if (inputMode == INPUT_LOCKED && !isPlayer) {
                        offX = 0;
                        offY = 0;
                    } else {
                        offX = MathUtils.lerp(0f, 32f * ((n.y - c.y) - (n.x - c.x)),
                                Math.min(1f, turnTime * 1.6f));
                        offY = MathUtils.lerp(0f, 16f * ((n.y - c.y) + (n.x - c.x)),
                                Math.min(1f, turnTime * 1.6f));
                    }
                    sprite = (Sprite) standing[currentKind].getKeyFrame(currentTime, true);
                    sprite.setColor(currentPiece.palette, 1f, 1f, 1f);
                    //MathUtils.clamp((float) fog.getNoise(32 * (y - x) + offX + 9f, 16 * (y + x) + offY + 13f, currentTime * 60) * 0.7f + 0.7f, 0.1f, 1f)
                    sprite.setPosition(32 * (y - x) + offX + 9f, 16 * (y + x) + offY + 13f);
                    sprite.draw(batch);
                    batch.setColor(Math.max(1, currentPiece.paint) / 255f, 0, 1, 1);
                    font.draw(batch, currentPiece.stats, 32 * (y - x) + offX + 9f, 16 * (y + x) + offY + 73f,
                            48f, Align.center, true);
                    //batch.setColor(-0x1.fffffep126f); // white as a packed float
                }
            }
        }
    }
    //batch.setColor(1f / 255f, 1f, 1f, 1f);
    //font.draw(batch, "DC: " + drawCalls + ", TBINDS: " + textureBindings, position.x, position.y, 100f, Align.center, true);
    batch.end();
    int drawCalls = glp.getDrawCalls();
    int textureBindings = glp.getTextureBindings();
    tempSB.setLength(0);
    tempSB.append(Gdx.graphics.getFramesPerSecond()).append(" FPS, Draw Calls: ").append(drawCalls)
            .append(", Texture Binds: ").append(textureBindings);
    screenPosition.set(16, 8);
    batch.begin();
    viewport.unproject(screenPosition);
    font.draw(batch, tempSB, screenPosition.x, screenPosition.y);
    //font.draw(batch, displayString, -300, 1160); //state.world.mapGen.atlas.getAt(guiRandom.between(2, 26))
    //batch.setColor(-0x1.fffffep126f); // white as a packed float
    batch.end();
    //drawCalls = GLProfiler.drawCalls;
    //textureBindings = GLProfiler.textureBindings;
}

From source file:it.alcacoop.fourinaline.actors.BoardImage.java

License:Open Source License

public void layout() {
    if (drawable == null)
        return;/*from  w w w . j  ava  2  s.c om*/

    float regionWidth = drawable.getMinWidth();
    float regionHeight = drawable.getMinHeight();
    float width = getWidth();
    float height = getHeight();

    Vector2 size = scaling.apply(regionWidth, regionHeight, width, height);
    imageWidth = size.x;
    imageHeight = size.y;

    if ((align & Align.left) != 0)
        imageX = 0;
    else if ((align & Align.right) != 0)
        imageX = (int) (width - imageWidth);
    else
        imageX = (int) (width / 2 - imageWidth / 2);

    if ((align & Align.top) != 0)
        imageY = (int) (height - imageHeight);
    else if ((align & Align.bottom) != 0)
        imageY = 0;
    else
        imageY = (int) (height / 2 - imageHeight / 2);

    if (fbo1 == null) {
        fbo1 = new FrameBuffer(Format.RGBA8888, (int) getWidth(), (int) getHeight(), false);
        fbo2 = new FrameBuffer(Format.RGBA8888, (int) getWidth(), (int) getHeight(), false);
    }

    SpriteBatch sb = new SpriteBatch();
    Matrix4 matrix = new Matrix4();
    matrix.setToOrtho2D(0, 0, getWidth(), getHeight()); // here is the actual size you want
    sb.setProjectionMatrix(matrix);

    fbo1.begin();
    sb.begin();
    Gdx.gl.glClearColor(1, 1, 1, 0);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    if (drawable != null) {
        for (int x = 0; x < nx; x++)
            for (int y = 0; y < ny; y++) {
                sb.draw(mask, x * xdim, y * ydim, 0, 0, xdim, ydim, 1, 1, 0);
            }
    }
    sb.end();
    fbo1.end();

    fbo2.begin();
    sb.setShader(shader);
    sb.begin();
    Gdx.gl.glClearColor(1, 1, 1, 0);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE1);
    wood.bind();
    shader.setUniformi("u_wood", 1);

    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
    sb.draw(fbo1.getColorBufferTexture(), 0, 0, getWidth(), getHeight());
    sb.end();
    shader.end();
    sb.setShader(null);
    fbo2.end();
}

From source file:it.alcacoop.fourinaline.actors.Checker.java

License:Open Source License

public void setColor(int color) {
    this.color = color;
    rotation = rnd.nextFloat() * 360;//from  w  w w  . j a va  2s. com
    Sprite sprite;
    sprite = new Sprite(r1);
    sprite.setRotation(rotation);

    double a = (double) r1.getRegionWidth();
    double b = (double) wood.getWidth();
    float d = (float) (a / b);

    float x = (rnd.nextFloat() * d);
    float y = (rnd.nextFloat() * d);

    fbo.begin();
    Gdx.gl.glClearColor(1, 1, 1, 0);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    sb.setShader(shader);
    shader.begin();
    sb.begin();
    shader.setUniformf("u_sx", x);
    shader.setUniformf("u_sy", y);
    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE1);
    wood.bind();
    shader.setUniformi("u_wood", 1);
    Gdx.gl20.glActiveTexture(GL20.GL_TEXTURE0);
    sprite.draw(sb);
    sb.end();
    shader.end();
    sb.setShader(null);
    fbo.end();
    reg = new TextureRegion(fbo.getColorBufferTexture());
}