List of usage examples for com.badlogic.gdx.graphics GL20 GL_ONE_MINUS_SRC_ALPHA
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
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 www . ja va 2 s .c o m*/ 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.prisonbreak.game.MapControlRenderer.java
@Override public void render() { if (state == STATE.ONGOING) { player.update();/* www . j a v a 2 s . com*/ 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 ww . j a va 2 s .com*/ 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 .ja v a 2 s . c o 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);/* ww w. j a v a 2s . co m*/ shapeRenderer.setProjectionMatrix(cam.combined); shapeRenderer.begin(ShapeType.Filled); if (world.lava_ != null) { world.lava_.cam_y = cam.position.y; world.lava_.render(batch, shapeRenderer); } 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);/*from w w w . j a va2 s .c o m*/ shapeRenderer.setProjectionMatrix(cam.combined); shapeRenderer.begin(ShapeType.Filled); if (world.lava_ != null) { world.lava_.cam_y = cam.position.y; world.lava_.renderTop(batch, shapeRenderer); } shapeRenderer.end(); }
From source file:com.retrom.volcano.game.WorldRenderer.java
License:Apache License
private void renderBlackBottomFade() { if (world.gameState != World.State.GAME) { return;//from w w w . j av a 2 s . 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.shatteredpixel.shatteredpixeldungeon.effects.Beam.java
License:Open Source License
@Override public void draw() { Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE); super.draw(); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); }
From source file:com.shatteredpixel.shatteredpixeldungeon.effects.Flare.java
License:Open Source License
@Override public void draw() { super.draw(); if (lightMode) { Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE); drawRays();/*from w w w . ja v a 2s .com*/ Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); } else { drawRays(); } }
From source file:com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene.java
License:Open Source License
@Override public void create() { super.create(); int gameversion = ShatteredPixelDungeon.version(); if (gameversion != Game.versionCode) { //new intro, make older players see it again. if (gameversion < 9) ShatteredPixelDungeon.intro(true); Game.switchScene(WelcomeScene.class); }/*from w w w .j ava2s . c o m*/ Music.INSTANCE.play(Assets.THEME, true); Music.INSTANCE.volume(1f); uiCamera.visible = false; int w = Camera.main.width; int h = Camera.main.height; Archs archs = new Archs(); archs.setSize(w, h); add(archs); Image title = BannerSprites.get(BannerSprites.Type.PIXEL_DUNGEON); add(title); float height = title.height + (ShatteredPixelDungeon.landscape() ? DashboardItem.SIZE : DashboardItem.SIZE * 2); title.x = (w - title.width()) / 2; title.y = (h - height) / 2; placeTorch(title.x + 18, title.y + 20); placeTorch(title.x + title.width - 18, title.y + 20); Image signs = new Image(BannerSprites.get(BannerSprites.Type.PIXEL_DUNGEON_SIGNS)) { private float time = 0; @Override public void update() { super.update(); am = (float) Math.sin(-(time += Game.elapsed)); } @Override public void draw() { Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE); super.draw(); Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); } }; signs.x = title.x; signs.y = title.y; add(signs); DashboardItem btnBadges = new DashboardItem(TXT_BADGES, 3) { @Override protected void onClick() { ShatteredPixelDungeon.switchNoFade(BadgesScene.class); } }; add(btnBadges); DashboardItem btnAbout = new DashboardItem(TXT_ABOUT, 1) { @Override protected void onClick() { ShatteredPixelDungeon.switchNoFade(AboutScene.class); } }; add(btnAbout); DashboardItem btnPlay = new DashboardItem(TXT_PLAY, 0) { @Override protected void onClick() { ShatteredPixelDungeon.switchNoFade(StartScene.class); } }; add(btnPlay); DashboardItem btnHighscores = new DashboardItem(TXT_HIGHSCORES, 2) { @Override protected void onClick() { ShatteredPixelDungeon.switchNoFade(RankingsScene.class); } }; add(btnHighscores); if (ShatteredPixelDungeon.landscape()) { float y = (h + height) / 2 - DashboardItem.SIZE; btnHighscores.setPos(w / 2 - btnHighscores.width(), y); btnBadges.setPos(w / 2, y); btnPlay.setPos(btnHighscores.left() - btnPlay.width(), y); btnAbout.setPos(btnBadges.right(), y); } else { btnBadges.setPos(w / 2 - btnBadges.width(), (h + height) / 2 - DashboardItem.SIZE); btnAbout.setPos(w / 2, (h + height) / 2 - DashboardItem.SIZE); btnPlay.setPos(w / 2 - btnPlay.width(), btnAbout.top() - DashboardItem.SIZE); btnHighscores.setPos(w / 2, btnPlay.top()); } BitmapText source = new BitmapText("PD v 1.7.5", font1x); source.measure(); source.hardlight(0x444444); source.x = w - source.width(); source.y = h - source.height(); add(source); BitmapText version = new BitmapText("v " + Game.version + "", font1x); version.measure(); version.hardlight(0xCCCCCC); version.x = w - version.width(); version.y = h - version.height() - source.height(); add(version); PrefsButton btnPrefs = new PrefsButton(); btnPrefs.setPos(0, 0); add(btnPrefs); ExitButton btnExit = new ExitButton(); btnExit.setPos(w - btnExit.width(), 0); add(btnExit); fadeIn(); }