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

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

Introduction

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

Prototype

int GL_ONE_MINUS_SRC_ALPHA

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

Click Source Link

Usage

From source file:com.cyphercove.doublehelix.MainRenderer.java

License:Apache License

@Override
public void create() {
    if (settingsAdapter != null)
        settingsAdapter.updateAllSettings();

    fader = new FullScreenFader(0, 1.5f);
    disposables.add(fader);/*ww  w. ja v a  2 s  . c  om*/

    GaussianBlurShaderProvider gaussianBlurShaderProvider = new GaussianBlurShaderProvider();

    bloom = new GaussianBlur(8f, false, true, gaussianBlurShaderProvider);
    bloom.setClearColor(Color.BLACK);
    bloom.setDepthTestingToScene(false);
    bloom.setBlending(true, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
    disposables.add(bloom);

    rearDOFBlur = new GaussianBlur(8f, true, true, gaussianBlurShaderProvider);
    rearDOFBlur.setDepthTestingToScene(true);
    rearDOFBlur.setBlending(false, 0, 0);
    disposables.add(rearDOFBlur);

    cam = new DepthOfFieldCamera(0.10f, 3.5f, 1f, 28f);

    needFinishCreate = true;
    firstFrameDrawn = false;

    //Enable point rendering for use when flake particles setting is off.
    Gdx.gl.glEnable(GL20.GL_VERTEX_PROGRAM_POINT_SIZE);
    if (Gdx.app.getType() == Application.ApplicationType.Desktop) {
        Gdx.gl.glEnable(0x8861); // GL_POINT_OES
    }
}

From source file:com.cyphercove.doublehelix.Particle.java

License:Apache License

public Particle(TextureRegion textureRegion, Texture pointTexture) {
    super();/*  w w  w  .  j a v a2  s .  com*/
    decal = new DecalPlus();
    decal.setTextureRegion(textureRegion);
    decal.setBlending(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);

    point = new BillboardDecal();
    point.setTexture(pointTexture);
    point.setBlending(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
}

From source file:com.cyphercove.doublehelix.UnlitShader.java

License:Apache License

@Override
public void begin(Camera camera, RenderContext context) {
    context.setDepthTest(GL20.GL_NONE);//from  w w w.  java 2  s . c o  m

    program.begin();
    viewProjTrans.set(camera.combined);

    context.setDepthTest(GL20.GL_LEQUAL);
    context.setCullFace(GL20.GL_BACK);
    context.setBlending(false, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    texture.bind(0);
    program.setUniformi(u_texture, 0);
}

From source file:com.cyphercove.lwptools.core.FullScreenFader.java

License:Apache License

public void render(float deltaTime) {
    if (elapsed >= fadeTime)
        return;/*from  w w w  .j ava 2 s  . c o  m*/

    if (delay > 0) {
        delay -= deltaTime;
    }

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

    color.a = delay > 0 ? 1f : 1f - Interpolation.fade.apply(elapsed / fadeTime);

    if (shader == null)
        createShader();
    shader.begin();
    shader.setUniformf(u_color, color);
    mesh.render(shader, GL20.GL_TRIANGLE_FAN);

    shader.end();

    if (delay <= 0)
        elapsed += deltaTime;
}

From source file:com.esotericsoftware.spine.superspineboy.View.java

License:Open Source License

void render() {
    viewport.apply();//  w  w w  .  j a  va 2 s.co  m

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    if (ui.bgButton.isChecked()) {
        mapRenderer.setBlending(false);
        mapRenderer.render(mapLayersOpaque1);

        mapRenderer.setBlending(true);
        mapRenderer.render(mapLayersBackground2);
    }

    batch.begin();
    // Draw enemies.
    for (Enemy enemy : model.enemies) {
        enemy.view.skeleton.getColor().a = Math.min(1, enemy.deathTimer / Enemy.fadeTime);
        skeletonRenderer.draw(batch, enemy.view.skeleton);
    }
    // Draw player.
    if (player.collisionTimer < 0 || (int) (player.collisionTimer / flashTime) % 3 != 0)
        skeletonRenderer.draw(batch, player.view.skeleton);
    batch.end();

    if (ui.bgButton.isChecked()) {
        mapRenderer.setBlending(false);
        mapRenderer.render(mapLayersOpaque3);

        mapRenderer.setBlending(true);
        mapRenderer.render(mapForegroundLayers4);
    }

    batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
    batch.begin();

    // Draw bullets.
    TextureRegion bulletRegion = assets.bulletRegion;
    float bulletWidth = bulletRegion.getRegionWidth() * scale;
    float bulletHeight = bulletRegion.getRegionHeight() * scale / 2;
    for (int i = 2, n = model.bullets.size; i < n; i += 5) {
        float x = model.bullets.get(i), y = model.bullets.get(i + 1);
        float angle = model.bullets.get(i + 2);
        float vx = MathUtils.cosDeg(angle);
        float vy = MathUtils.sinDeg(angle);
        // Adjust position so bullet region is drawn with the bullet position in the center of the fireball.
        x -= vx * bulletWidth * 0.65f;
        y -= vy * bulletWidth * 0.65f;
        x += vy * bulletHeight / 2;
        y += -vx * bulletHeight / 2;
        batch.draw(bulletRegion, x, y, 0, 0, bulletWidth, bulletHeight, 1, 1, angle);
    }

    // Draw hit markers.
    TextureRegion hitRegion = assets.hitRegion;
    Color color = batch.getColor().set(1, 1, 1, 1);
    float hitWidth = hitRegion.getRegionWidth() * scale;
    float hitHeight = hitRegion.getRegionWidth() * scale;
    for (int i = hits.size - 4; i >= 0; i -= 4) {
        float time = hits.get(i);
        float x = hits.get(i + 1);
        float y = hits.get(i + 2);
        float angle = hits.get(i + 3);
        color.a = time / bulletHitTime;
        batch.setColor(color);
        float vx = MathUtils.cosDeg(angle);
        float vy = MathUtils.sinDeg(angle);
        // Adjust position so bullet region is drawn with the bullet position in the center of the fireball.
        x += vy * bulletHeight * 0.2f;
        y += -vx * bulletHeight * 0.2f;
        batch.draw(hitRegion, x - hitWidth / 2, y, hitWidth / 2, 0, hitWidth, hitHeight, 1, 1, angle);
    }
    batch.setColor(Color.WHITE);

    batch.end();
    batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    if (ui.bgButton.isChecked())
        mapRenderer.render(mapForegroundLayers5);

    ui.render();
}

From source file:com.gamejolt.mikykr5.ceidecpong.GameCore.java

License:Open Source License

@Override
public void create() {
    AsyncAssetLoader loader = AsyncAssetLoader.getInstance();

    // Set up rendering fields and settings.
    ShaderProgram.pedantic = false; // Not passing all variables to a shader will not close the game.
    batch = new SpriteBatch();
    batch.enableBlending();/*from  w ww .j  a v  a  2s.com*/
    batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    // Prepare the fading effect.
    Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
    pixmap.setColor(0, 0, 0, 1);
    pixmap.fill();
    fadeTexture = new Texture(pixmap);
    pixmap.dispose();

    // Create the initial interpolators and start with a fade in effect.
    alpha = new MutableFloat(1.0f);
    fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
    fadeIn = Tween.to(alpha, 0, 2.5f).target(0.0f).ease(TweenEquations.easeInQuint);
    fadeIn.start();
    fading = true;

    // Create application states.
    states = new BaseState[game_states_t.getNumStates()];

    try {
        states[game_states_t.LOGO_SCREEN.getValue()] = new LogoScreenState(this);
        states[game_states_t.MAIN_MENU.getValue()] = new MainMenuState(this);
        states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
        states[game_states_t.LOADING.getValue()] = new LoadingState(this);
        states[game_states_t.QUIT.getValue()] = null;
    } catch (IllegalArgumentException e) {
        Gdx.app.error(TAG, CLASS_NAME + ".create(): Illegal argument caught creating states: ", e);
        System.exit(1);
        return;
    }

    // Register every state as an AssetsLoadedListener if the state implements the interface.
    for (BaseState state : states) {
        if (state != null && state instanceof AssetsLoadedListener)
            loader.addListener((AssetsLoadedListener) state);
    }
    AsyncAssetLoader.freeInstance();
    loader = null;

    // Set the initial current and next states.
    currState = game_states_t.LOGO_SCREEN;
    nextState = null;
    this.setScreen(states[currState.getValue()]);

    // Set log level
    if (ProjectConstants.DEBUG) {
        Gdx.app.setLogLevel(Application.LOG_DEBUG);
    } else {
        Gdx.app.setLogLevel(Application.LOG_NONE);
    }
}

From source file:com.github.fauu.helix.core.GeneralShader.java

License:Open Source License

@Override
public void begin(Camera camera, RenderContext context) {
    this.camera = camera;
    this.context = context;

    program.begin();/*  w ww  .  ja v a 2s  .  c o  m*/
    program.setUniformMatrix(u_projTrans, camera.combined);

    context.setBlending(true, GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    context.setCullFace(GL20.GL_BACK);
    context.setDepthTest(GL20.GL_LEQUAL, 0, 1);
    context.setDepthMask(true);
}

From source file:com.github.fauu.helix.core.Object.java

License:Open Source License

public Object(Vector2 position, String modelName, Model model, int elevation, Direction facing) {
    this.position = position;
    this.elevation = elevation;
    this.modelInstance = new ModelInstance(model);
    this.modelName = modelName;
    this.facing = facing;

    modelInstance.transform.setToTranslation(position.x, elevation, position.y + 1).rotate(new Vector3(0, 1, 0),
            -90);/*from w  ww .  j  ava  2  s .  c  om*/

    final TextureAttribute textureAttribute = (TextureAttribute) modelInstance.materials.first()
            .get(TextureAttribute.Diffuse);
    textureAttribute.textureDescription.magFilter = Texture.TextureFilter.Nearest;
    textureAttribute.textureDescription.minFilter = Texture.TextureFilter.Nearest;
    modelInstance.materials.first().set(textureAttribute);

    modelInstance.materials.first().set(new ColorAttribute(ColorAttribute.createDiffuse(Color.WHITE)));
    modelInstance.materials.first().set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
    //modelInstance.materials.first().set(new FloatAttribute(FloatAttribute.AlphaTest, 0.14f));
}

From source file:com.github.fauu.helix.core.Renderer.java

License:Open Source License

public void render(Camera camera, Array<RenderableProvider> renderableProviders, Array<Decal> decals) {
    final GL20 gl = Gdx.graphics.getGL20();

    gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL20.GL_BLEND);//w ww  .  j  av  a  2s.  c  o m
    gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    if (decalBatch == null) {
        defaultCameraGroupStrategy = new CameraGroupStrategy(camera);
        waterCameraGroupStrategy = new CameraGroupStrategy(waterCamera);

        decalBatch = new DecalBatch(defaultCameraGroupStrategy);
    }

    //waterCamera.moveTo(new Vector2(13, 19));
    /* Render objects to framebuffer */
    fb.begin();
    gl.glClearColor(0, 0, 0, 0);
    gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL20.GL_BLEND);
    gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    renderContext.begin();
    modelBatch.begin(waterCamera);
    for (int i = 1; i < renderableProviders.size - 1; i++) {
        modelBatch.render(renderableProviders.get(i));
    }
    modelBatch.end();
    renderContext.end();

    decalBatch.setGroupStrategy(waterCameraGroupStrategy);
    if (decals != null) {
        decals.first().rotateX(50);
        decalBatch.add(decals.first());
        decalBatch.flush();
        decals.first().rotateX(-50);
    }

    //    Vector3 waterPos = waterCamera.project(new Vector3(8, 0, 19));
    //    reflectionPixmap = ScreenUtils.getFrameBufferPixmap((int) waterPos.x, (int) waterPos.y, 348, 261);
    //    reflectionPixmap = ScreenUtils.getFrameBufferPixmap(0, 0, 800, 600);

    fb.end();

    //    if (reflectionTexture == null) {
    //      reflectionTexture = new Texture(reflectionPixmap);
    //    } else {
    //      reflectionTexture.draw(reflectionPixmap, 0, 0);
    //    }

    ((WaterData) ((ModelInstance) renderableProviders
            .get(renderableProviders.size - 1)).userData).reflectionTexture = fb.getColorBufferTexture();

    /* Render objects and terrain to the screen */
    renderContext.begin();
    modelBatch.begin(camera);
    modelBatch.render(renderableProviders);
    modelBatch.end();
    renderContext.end();
    decalBatch.setGroupStrategy(defaultCameraGroupStrategy);
    if (decals != null) {
        decalBatch.add(decals.first());
    }
    decalBatch.flush();

    spriteBatch.begin();
    spriteBatch.enableBlending();
    spriteBatch.draw(fb.getColorBufferTexture(), 0, 0, 800, 600);
    spriteBatch.end();

}

From source file:com.github.fauu.helix.displayable.AreaDisplayable.java

License:Open Source License

public AreaDisplayable(Model model) {
    instance = new ModelInstance(model);

    animationController = new AnimationController(instance);

    instance.transform.rotate(new Vector3(1, 0, 0), 90);

    for (Material material : instance.materials) {
        TextureAttribute ta = (TextureAttribute) material.get(TextureAttribute.Diffuse);

        ta.textureDescription.magFilter = Texture.TextureFilter.Nearest;
        ta.textureDescription.minFilter = Texture.TextureFilter.Nearest;

        material.set(ta);//from  w ww  .j a v a  2s. c  o  m
        material.set(ColorAttribute.createDiffuse(Color.WHITE));

        BlendingAttribute ba = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

        material.set(ba);
    }
}