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

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

Introduction

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

Prototype

int GL_SRC_ALPHA

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

Click Source Link

Usage

From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzleGameMenu.java

License:Open Source License

@Override
public void create() {
    timer = new Timer();

    Gdx.app.setLogLevel(Application.LOG_ERROR);

    Gdx.app.log("PhysicsPuzzleGameMenu", "Creating application PhysicsPuzzleGameMenu");

    preferences = Gdx.app.getPreferences("PhysicsPuzzle");

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

    // ui stuff/*from  w  w w .  j av  a 2 s  .  co  m*/
    ScreenViewport sv = new ScreenViewport();
    float ui_scale = (float) Math.abs(Math.log(Gdx.graphics.getDensity())) * 2f;
    sv.setUnitsPerPixel(1f / ui_scale);
    this.stage = new Stage(sv);
    skin = new Skin(Gdx.files.internal("ui/custom/custom.json"));

    // backgrounds and thumbnails are here
    textureAtlas = new TextureAtlas("images/packed/packed.atlas");
    availableRegions = findLinesThatContain("images/packed/packed.atlas", "thumbnails");

    // input
    inputMultiplexer = new InputMultiplexer();
    Gdx.input.setInputProcessor(inputMultiplexer);
    inputMultiplexer.addProcessor(stage);

    // background stuff
    polygonBatch = new PrettyPolygonBatch();
    backgroundCamera = new OrthographicCamera();

    showMainMenu();

}

From source file:org.ams.testapps.prettypaint.CircleAndBackground.java

License:Open Source License

@Override
public void create() {
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.input.setInputProcessor(this);

    float w = Gdx.graphics.getWidth() * 0.5f;
    float h = Gdx.graphics.getHeight() * 0.5f;
    camera = new OrthographicCamera(10, 10 * (h / w));

    batch = new PrettyPolygonBatch();

    // create the vertices used for the circle
    float radius = 2f;
    Vector2 v = new Vector2(radius, 0);
    float angle = MathUtils.PI2 / 300;
    for (float rad = 0; rad <= MathUtils.PI2; rad += angle) {
        v.rotateRad(angle);//  w  w  w.jav  a  2  s.co  m
        circleVertices.add(new Vector2(v));
    }

    // prepare circle
    outlinePolygon = new OutlinePolygon();
    outlinePolygon.setColor(Color.BLACK);
    outlinePolygon.setClosedPolygon(false);

    // prepare shadow around circle
    shadowPolygon = new OutlinePolygon();
    shadowPolygon.setColor(new Color(0, 0, 0, 0.4f));
    shadowPolygon.setHalfWidth(outlinePolygon.getHalfWidth() * 3);
    shadowPolygon.setClosedPolygon(false);

    // prepare the vertices for background and frame
    float hw = camera.viewportWidth * 0.5f;
    float hh = camera.viewportHeight * 0.5f;

    Array<Vector2> cameraBounds = new Array<Vector2>();
    cameraBounds.add(new Vector2(-hw, -hh));
    cameraBounds.add(new Vector2(hw, -hh));
    cameraBounds.add(new Vector2(hw, hh));
    cameraBounds.add(new Vector2(-hw, hh));

    // prepare background
    texture = new Texture("images/for packing/backgrounds-dark/escheresque_ste.png");
    texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    background = new TexturePolygon();
    background.setTextureRegion(new TextureRegion(texture));
    background.setScale(0.96f);
    background.setVertices(cameraBounds);

}

From source file:org.ams.testapps.prettypaint.SaveThingAsPng.java

License:Open Source License

@Override
public void create() {
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    Gdx.input.setInputProcessor(this);

    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera(10, 10 * (h / w));

    polygonBatch = new PrettyPolygonBatch();

    world = new PPWorld();

    texture = new Texture("skulls.png");
    texture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);

    square = addSquare(texture);// w  w w .j  a  v a  2 s.  c  o  m
    circle = addCircle(texture);
    polygon = addPolygon(texture);

}

From source file:org.ams.testapps.prettypaint.TextureAlignmentTest2.java

License:Open Source License

@Override
public void create() {
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    // prepare camera and camera controls
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera(10, 10 * (h / w));
    cameraNavigator = new CameraNavigator(camera);
    Gdx.input.setInputProcessor(cameraNavigator);

    polygonBatch = new PrettyPolygonBatch();

    // load textures
    texture = new Texture("images/puzzles/stockvault-cow131648.jpg");
    textureAtlas = new TextureAtlas("images/packed/packed.atlas");
    testTextureRegions = new Array<TextureRegion>();
    testTextureRegions.add(new TextureRegion(texture));
    for (TextureRegion textureRegion : textureAtlas.getRegions()) {
        testTextureRegions.add(textureRegion);
    }/*w ww  .java 2 s.  c  o  m*/

    // prepare TexturePolygons
    Array<Vector2> vertices = new Array<Vector2>();
    vertices.add(new Vector2(0, 0));
    vertices.add(new Vector2(2, 0));
    vertices.add(new Vector2(2, 2));
    vertices.add(new Vector2(0, 2));
    Util.translateSoCentroidIsAtOrigin(vertices);

    texturePolygon = new TexturePolygon();
    texturePolygon.setVertices(vertices);
    texturePolygon.setTextureRegion(new TextureRegion(texture));

    shapeRenderer = new ShapeRenderer();
    shapeRenderer.setAutoShapeType(true);

}

From source file:org.anism.lotw.LOTW.java

License:Open Source License

@Override
public void create() {
    dpi = Gdx.graphics.getDensity();/*from  w w w .  j a  v a2 s  . co m*/

    if (actionResolver.getSignedInGPGS()) {
    } else {
        actionResolver.loginGPGS();
    }

    G = new Glob(this);
    G.clear();
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    buttonWidth = Math.min(G.width / 4 - 8 * dpi, 196 * dpi);
    settingsButtonHeight = Math.min((G.height - 96 * dpi) / 4 - 8 * dpi, 88 * dpi);
    /*
    Texture upTexture = new Texture(Gdx.files.internal("images/sphere-lightgrey-24.png"));
    Texture downTexture = new Texture(Gdx.files.internal("images/sphere-greylight-24.png"));
    NinePatch buttonPatchUp = new NinePatch(upTexture, 11, 11, 11, 11);
    NinePatch buttonPatchDown = new NinePatch(downTexture, 11, 11, 11, 11);
    */

    //intro = new Stage();
    settings = new Stage();
    colorSettings = new Stage();
    controlSettings = new Stage();
    modeSettings = new Stage();
    loginSettings = new Stage();
    bottomSettings = new Stage();

    about = new TouchStage();
    instructions = new TouchStage();
    statistics = new TouchStage();
    game = new TouchStage() {
        @Override
        public void draw() {
            G.tick(true, true);
            G.input(true);
            G.clear();
            G.draw();
            super.act();
            super.draw();
            Gdx.gl.glEnable(GL20.GL_BLEND);
        }
    };
    over = new TouchStage();

    initEverything();

    setStage(instructions);
}

From source file:org.bladecoder.bladeengine.model.Scene.java

License:Apache License

public void draw(SpriteBatch spriteBatch) {

    if (background != null) {
        spriteBatch.disableBlending();/*from ww w.j  a va2s . co  m*/

        float x = 0;

        for (Texture tile : background) {
            spriteBatch.draw(tile, x, 0f);
            x += tile.getWidth();
        }

        spriteBatch.enableBlending();
    }

    for (Actor a : orderedActors) {
        if (a instanceof SpriteActor)
            ((SpriteActor) a).draw(spriteBatch);
    }

    for (SpriteActor a : fgActors) {
        a.draw(spriteBatch);
    }

    // Draw the light map
    if (lightMap != null) {
        // Multiplicative blending for light maps
        spriteBatch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ZERO);

        float x = 0;

        for (Texture tile : lightMap) {
            spriteBatch.draw(tile, x, 0f);
            x += tile.getWidth();
        }

        spriteBatch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    if (overlay != null) {
        overlay.draw(spriteBatch);
    }

    if (EngineLogger.debugMode() && EngineLogger.getDebugLevel() == EngineLogger.DEBUG1) {

        StringBuilder sb = new StringBuilder();

        for (Actor a : orderedActors) {
            Rectangle r = a.getBBox().getBoundingRectangle();
            sb.setLength(0);
            sb.append(a.getId());
            if (a.getState() != null)
                sb.append(".").append(a.getState());
            // sb.append(" (").append((int) r.getX()).append(", ");
            // sb.append((int) r.getY()).append(", ").append((int)
            // r.getWidth());
            // sb.append(", ").append((int) r.getHeight()).append(") ");
            EngineLogger.getDebugFont().draw(spriteBatch, sb.toString(), r.getX(), r.getY());
        }

    }
}

From source file:org.bladecoder.bladeengine.util.Utils3D.java

License:Apache License

public static void createFloor() {

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();//from ww  w  . j a  v  a  2  s.c o  m
    MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal | Usage.Color,
            new Material(ColorAttribute.createDiffuse(Color.WHITE)));
    mpb.setColor(1f, 1f, 1f, 1f);
    //      mpb.box(0, -0.1f, 0, 10, .2f, 10);
    mpb.rect(-10, 0, -10, -10, 0, 10, 10, 0, 10, 10, 0, -10, 0, 1, 0);
    floorModel = modelBuilder.end();
    floorInstance = new ModelInstance(floorModel);

    // TODO Set only when FBO is active
    floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
}

From source file:patch.libgdx.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  w w  . jav a 2s  .  c  om
        batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    }

    Particle[] particles = this.particles;
    boolean[] active = this.active;

    if (culling) {
        for (int i = 0, n = active.length; i < n; i++) {
            if (!active[i]) {
                continue;
            }

            final Particle particle = particles[i];
            final float x = particle.getX();

            if (x + particle.getWidth() < cullMin || x > cullMax) {
                continue;
            }

            particle.draw(batch);
        }
    } else {
        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:seventh.client.gfx.effects.particle_system.BlendingSpriteParticleRenderer.java

License:Open Source License

@Override
public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) {
    int src = canvas.getSrcBlendFunction();
    int dst = canvas.getDstBlendFunction();
    //canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_FUNC_ADD);
    canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
    Gdx.gl20.glBlendEquation(GL20.GL_FUNC_ADD);

    Vector2f cameraPos = camera.getRenderPosition(alpha);
    for (int i = 0; i < particles.numberOfAliveParticles; i++) {
        Sprite sprite = particles.sprite[i];
        Vector2f pos = particles.pos[i];
        sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y);
        sprite.setScale(particles.scale[i]);
        sprite.setColor(particles.color[i]);
        sprite.setRotation(particles.rotation[i]);
        canvas.drawRawSprite(sprite);/*from   w ww .j  av a 2  s  .c o m*/
    }

    canvas.setBlendFunction(src, dst);
}

From source file:seventh.client.gfx.effects.particle_system.FireParticleRenderer.java

License:Open Source License

@Override
public void render(Canvas canvas, Camera camera, float alpha, ParticleData particles) {
    int src = canvas.getSrcBlendFunction();
    int dst = canvas.getDstBlendFunction();
    //canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_FUNC_ADD);
    canvas.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
    Gdx.gl20.glBlendEquation(GL20.GL_FUNC_ADD);

    Vector2f cameraPos = camera.getRenderPosition(alpha);
    for (int i = 0; i < particles.numberOfAliveParticles; i++) {
        Sprite sprite = particles.sprite[i];
        Vector2f pos = particles.pos[i];
        sprite.setPosition(pos.x - cameraPos.x, pos.y - cameraPos.y);
        sprite.setScale(particles.scale[i]);
        sprite.setColor(particles.color[i]);
        canvas.drawRawSprite(sprite);//from  w w w  .ja v  a 2s  .  c o  m
    }

    canvas.setBlendFunction(src, dst);
}