Java Code Examples for com.badlogic.gdx.graphics.g2d.Batch#begin()

The following examples show how to use com.badlogic.gdx.graphics.g2d.Batch#begin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridRenderer.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void draw (Batch batch, float parentAlpha) {
	super.draw(batch, parentAlpha);
	batch.end();

	shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());

	final float worldWidth = stage.getViewport().getWorldWidth() * camera.zoom;
	final float worldHeight = stage.getViewport().getWorldHeight() * camera.zoom;

	final Vector3 position = stage.getViewport().getCamera().position;

	float x = position.x - worldWidth / 2f;
	float y = position.y - worldHeight / 2f;

	shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
	drawGrid(x, y, worldWidth, worldHeight);
	shapeRenderer.end();

	batch.begin();
}
 
Example 2
Source File: ShapeWidget.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    tmp.set(0, 0);
    localToStageCoordinates(tmp);

    drawBg(batch, parentAlpha);

    batch.end();
    shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Line);

    drawGrid(batch, parentAlpha);
    drawShape(batch, parentAlpha);
    drawTools(batch, parentAlpha);

    shapeRenderer.end();
    batch.begin();

}
 
Example 3
Source File: BvBWorkspace.java    From talos with Apache License 2.0 6 votes vote down vote up
@Override
public void drawContent(Batch batch, float parentAlpha) {
    batch.end();
    drawGrid(batch, parentAlpha);
    batch.begin();

    drawVFXBefore(batch, parentAlpha);
    drawSpine(batch, parentAlpha);
    drawVFX(batch, parentAlpha);


    drawTools(batch, parentAlpha);

    if(showingTools) {
        topUI.draw(batch, parentAlpha);
    }
}
 
Example 4
Source File: RenderWidget.java    From Mundus with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    if (renderer == null || cam == null) return;

    // render part of the ui & pause rest
    batch.end();

    vec.set(getOriginX(), getOriginY());
    vec = localToStageCoordinates(vec);
    final int width = (int) getWidth();
    final int height = (int) getHeight();

    // apply widget viewport
    viewport.setScreenBounds((int) vec.x, (int) vec.y, width, height);
    viewport.setWorldSize(width * viewport.getUnitsPerPixel(), height * viewport.getUnitsPerPixel());
    viewport.apply();

    // render 3d scene
    renderer.render(cam);

    // re-apply stage viewport
    UI.INSTANCE.getViewport().apply();

    // proceed ui rendering
    batch.begin();
}
 
Example 5
Source File: GradientDrawable.java    From skin-composer with MIT License 6 votes vote down vote up
@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();
    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];
}
 
Example 6
Source File: ColorFadeTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;

	if (interpolation != null) percent = interpolation.apply(percent);

	batch.begin();

	float fade = percent * 2;

	if (fade > 1.0f) {
		fade = 1.0f - (percent * 2 - 1.0f);
		color.a = 1.0f - fade;
		batch.setColor(color);

		batch.draw(nextScreenTexture, 0, 0, width / 2, height / 2, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(),
			1, 1, 0, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true);

	} else {

		color.a = 1.0f - fade;
		batch.setColor(color);

		batch.draw(currentScreenTexture, 0, 0, width / 2, height / 2, width, height, 1, 1, 0, 0, 0, (int)width, (int)height,
			false, true);

	}

	color.a = fade;

	batch.setColor(color);
	batch.draw(texture, 0, 0, width, height);
	batch.end();
	batch.setColor(Color.WHITE);

}
 
Example 7
Source File: AlphaFadingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float alpha) {
	alpha = Interpolation.fade.apply(alpha);
	batch.begin();
	batch.setColor(1, 1, 1, 1);
	batch.draw(currentScreenTexture, 0, 0, 0, 0, currentScreenTexture.getWidth(), currentScreenTexture.getHeight(), 1, 1, 0, 0,
		0, currentScreenTexture.getWidth(), currentScreenTexture.getHeight(), false, true);
	batch.setColor(1, 1, 1, alpha);
	batch.draw(nextScreenTexture, 0, 0, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), 1, 1, 0, 0, 0,
		nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true);
	batch.end();

}
 
Example 8
Source File: SlidingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;
	if (interpolation != null) percent = interpolation.apply(percent);

	switch (direction) {
	case LEFT:
		x = -width * percent;
		if (!slideOut) x += width;
		break;
	case RIGHT:
		x = width * percent;
		if (!slideOut) x -= width;
		break;
	case UP:
		y = height * percent;
		if (!slideOut) y -= height;
		break;
	case DOWN:
		y = -height * percent;
		if (!slideOut) y += height;
		break;
	}
	Texture texBottom = slideOut ? nextScreenTexture : currentScreenTexture;
	Texture texTop = slideOut ? currentScreenTexture : nextScreenTexture;

	batch.begin();
	batch.draw(texBottom, 0, 0, 0, 0, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true);
	batch.draw(texTop, x, y, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), 1, 1, 0, 0, 0,
		nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false, true);
	batch.end();

}
 
Example 9
Source File: SlicingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;
	int sliceWidth = (int)(width / slices.size);

	batch.begin();
	batch.draw(currentScreenTexture, 0, 0, 0, 0, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false, true);
	if (interpolation != null) percent = interpolation.apply(percent);
	for (int i = 0; i < slices.size; i++) {

		x = i * sliceWidth;

		float offsetY = height * (1 + slices.get(i) / (float)slices.size);
		switch (direction) {
		case UP:
			y = -offsetY + offsetY * percent;
			break;
		case DOWN:
			y = offsetY - offsetY * percent;
			break;
		case UPDOWN:
			if (i % 2 == 0) {
				y = -offsetY + offsetY * percent;
			} else {
				y = offsetY - offsetY * percent;
			}
			break;
		}
		batch.draw(nextScreenTexture, x, y, 0, 0, sliceWidth, nextScreenTexture.getHeight(), 1, 1, 0, i * sliceWidth, 0,
			sliceWidth, nextScreenTexture.getHeight(), false, true);
	}
	batch.end();
}
 
Example 10
Source File: RotatingTransition.java    From libgdx-transitions with Apache License 2.0 5 votes vote down vote up
@Override
public void render (Batch batch, Texture currentScreenTexture, Texture nextScreenTexture, float percent) {
	float width = currentScreenTexture.getWidth();
	float height = currentScreenTexture.getHeight();
	float x = 0;
	float y = 0;

	float scalefactor;

	switch (scaling) {
	case IN:
		scalefactor = percent;
		break;
	case OUT:
		scalefactor = 1.0f - percent;
		break;
	case NONE:
	default:
		scalefactor = 1.0f;
		break;
	}

	float rotation = 1;
	if (interpolation != null) rotation = interpolation.apply(percent);

	batch.begin();
	batch.draw(currentScreenTexture, 0, 0, width / 2, height / 2, width, height, 1, 1, 0, 0, 0, (int)width, (int)height, false,
		true);
	batch.draw(nextScreenTexture, 0, 0, width / 2, height / 2, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(),
		scalefactor, scalefactor, rotation * angle, 0, 0, nextScreenTexture.getWidth(), nextScreenTexture.getHeight(), false,
		true);
	batch.end();

}
 
Example 11
Source File: GdxHelper.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
public static void showStageEvents(final Stage stage) {
    EventListener listener = new EventListener() {
        private final Vector2 tmp = new Vector2();
        private Actor actor = new Actor() {
            @Override public void draw(Batch batch, float parentAlpha) {
                if (target == null)
                    return;
                batch.end();
                Config.shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
                Config.shapeRenderer.setProjectionMatrix(stage.getCamera().combined);
                Gdx.gl.glLineWidth(6);
                Config.shapeRenderer.setColor(Color.ORANGE);
                Vector2 pos = target.localToStageCoordinates(tmp.set(0, 0));
                float x = pos.x, y = pos.y;
                Vector2 top = target.localToStageCoordinates(tmp.set(target.getWidth(), target.getHeight()));
                float maxX = top.x, maxY = top.y;
                Config.shapeRenderer.rect(x, y, maxX - x, maxY - y);

                Config.shapeRenderer.end();
                batch.begin();
            }
        };

        {
            stage.addActor(actor);
        }

        public Actor target;

        @Override public boolean handle(Event event) {
            target = event.getTarget();
            return false;
        }
    };
    stage.addListener(listener);
}
 
Example 12
Source File: AnimationTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

  stage.act();
  stage.draw();

  float delta = Gdx.graphics.getDeltaTime();
  if (lockFps) {
    accumulator += delta;
    while (accumulator >= Animation.FRAME_DURATION) {
      lastUpdate = accumulator;
      accumulator -= Animation.FRAME_DURATION;
      anim.act(Animation.FRAME_DURATION);
    }
  } else {
    lastUpdate = delta;
    anim.act(delta);
  }

  Batch b = stage.getBatch();
  b.begin();
  Riiablo.fonts.consolas16.draw(b, String.valueOf(Gdx.graphics.getFramesPerSecond()), 0, Gdx.graphics.getHeight());
  Riiablo.fonts.consolas16.draw(b, String.valueOf(MathUtils.roundPositive(1 / lastUpdate)), 0, Gdx.graphics.getHeight() - 16);
  b.end();

  Riiablo.batch.begin(Riiablo.palettes.act1);
  anim.draw(Riiablo.batch, Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
  Riiablo.batch.end();
}
 
Example 13
Source File: StorageDownloadImageTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch) {
    if (img == null) return;
    batch.begin();
    batch.draw(img, 0, 0);
    batch.end();
}
 
Example 14
Source File: BadlogicTest.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch) {
    if (img == null) return;
    batch.begin();
    batch.draw(img, 0, 0);
    batch.end();
}
 
Example 15
Source File: FontMetricsTool.java    From riiablo with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

  stage.act();
  stage.draw();

  Batch b = stage.getBatch();
  b.begin();
  GlyphLayout consolas16Layout = Riiablo.fonts.consolas16.draw(b, STRING, 0, 550, 600, center ? Align.center : Align.left, true);
  b.end();

  PaletteIndexedBatch batch = Riiablo.batch;
  batch.begin(Riiablo.palettes.units);
  batch.setBlendMode(active.getBlendMode());
  GlyphLayout otherLayout = active.draw(batch, STRING, 0, 250, 600, center ? Align.center : Align.left, true);
  batch.end();

  if (debug) {
    ShapeRenderer shapes = Riiablo.shapes;
    shapes.begin(ShapeRenderer.ShapeType.Line);
    drawDebug(Riiablo.fonts.consolas16, consolas16Layout, 550);
    drawDebug(active, otherLayout, 250);
    shapes.end();
  }
}
 
Example 16
Source File: ModuleBoardWidget.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    batch.end();
    shapeRenderer.setProjectionMatrix(getStage().getCamera().combined);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    drawCurves();
    shapeRenderer.end();
    batch.begin();

    super.draw(batch, parentAlpha);
}
 
Example 17
Source File: SceneList.java    From bladecoder-adventure-engine with Apache License 2.0 5 votes vote down vote up
public TextureRegion getBgIcon(String atlas, String region) {

		// check here for dispose instead in project loading because the opengl
		// context lost in new project thread
		if (disposeBgCache) {
			dispose();
			disposeBgCache = false;
		}

		String s = atlas + "#" + region;
		TextureRegion icon = bgIconCache.get(s);

		if (icon == null) {
			Batch batch = getStage().getBatch();
			batch.end();

			try {
				icon = createBgIcon(atlas, region);
			} catch (Exception e) {
				EditorLogger.error("Error creating Background icon: " + atlas + "." + region);
			}

			if (icon == null) {
				EditorLogger.error("Error creating Background icon: " + atlas + "." + region);
				icon = Ctx.assetManager.getIcon("ic_no_scene");
			}

			bgIconCache.put(s, icon);

			batch.begin();

		}

		return icon;
	}
 
Example 18
Source File: ViewportWidget.java    From talos with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Batch batch, float parentAlpha) {
    batch.end();

    localToScreenCoordinates(temp.set(0, 0));
    int x = (int)temp.x;
    int y = (int)temp.y;

    localToScreenCoordinates(temp.set(getWidth(), getHeight()));

    int x2 = (int)temp.x;
    int y2 = (int)temp.y;

    int ssWidth = x2 - x;
    int ssHeight = y - y2;

    HdpiUtils.glViewport(x, Gdx.graphics.getHeight() - y, ssWidth, ssHeight);

    Gdx.gl.glClearColor(bgColor.r, bgColor.g, bgColor.b, 1f);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    float aspect = getWidth()/getHeight();

    camera.viewportHeight = camera.viewportWidth / aspect;

    camera.update();

    prevTransform.set(batch.getTransformMatrix());
    prevProjection.set(batch.getProjectionMatrix());
    batch.setProjectionMatrix(camera.combined);
    batch.setTransformMatrix(emptyTransform);

    batch.begin();
    drawContent(batch, parentAlpha);
    batch.end();

    HdpiUtils.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    batch.setProjectionMatrix(prevProjection);
    batch.setTransformMatrix(prevTransform);
    batch.begin();

    super.draw(batch, parentAlpha);
}
 
Example 19
Source File: PreviewWidget.java    From talos with Apache License 2.0 4 votes vote down vote up
@Override
public void drawContent(Batch batch, float parentAlpha) {
    batch.end();
    drawGrid(batch, parentAlpha * 0.5f);
    batch.begin();

    mid.set(0, 0);

    float imagePrefWidth = previewImage.getPrefWidth();
    float imagePrefHeight = previewImage.getPrefHeight();
    float scale = imagePrefHeight / imagePrefWidth;

    float imageWidth = previewController.getImageWidth();
    float imageHeight = imageWidth * scale;
    previewController.getPreviewBoxWidth();

    previewImage.setPosition(mid.x - imageWidth / 2, mid.y - imageHeight / 2);
    previewImage.setSize(imageWidth, imageHeight);
    if (previewController.isBackground()) {
        previewImage.draw(batch, parentAlpha);
    }

    spriteBatchParticleRenderer.setBatch(batch);

    batch.flush();
    glProfiler.enable();

    long timeBefore = TimeUtils.nanoTime();

    final ParticleEffectInstance particleEffect = TalosMain.Instance().TalosProject().getParticleEffect();
    particleEffect.render(particleRenderer);

    batch.flush();
    renderTime.put(TimeUtils.timeSinceNanos(timeBefore));
    trisCount = (int) (glProfiler.getVertexCount().value / 3f);
    glProfiler.disable();


    if (!previewController.isBackground()) {
        previewImage.draw(batch, parentAlpha);
    }

    // now for the drag points
    if(dragPoints.size > 0) {
        batch.end();
        tmpColor.set(Color.ORANGE);
        tmpColor.a = 0.8f;
        Gdx.gl.glLineWidth(1f);
        Gdx.gl.glEnable(GL20.GL_BLEND);
        Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
        shapeRenderer.setProjectionMatrix(batch.getProjectionMatrix());
        shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
        shapeRenderer.setColor(tmpColor);

        for (DragPoint point : dragPoints) {
            shapeRenderer.circle(point.position.x, point.position.y, 0.1f * camera.zoom, 15);
        }

        shapeRenderer.end();
        batch.begin();
    }
}
 
Example 20
Source File: Client.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void render() {
  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

  audio.update();

  Camera camera = viewport.getCamera();
  camera.update();
  batch.setProjectionMatrix(camera.combined);
  shapes.setProjectionMatrix(camera.combined);

  if (DEBUG_VIEWPORTS) {
    shapes.begin(ShapeRenderer.ShapeType.Filled);
    shapes.setColor(Color.DARK_GRAY);
    shapes.rect(0, 0, 854, 480);
    shapes.setColor(Color.GRAY);
    shapes.rect(0, 0, 640, 480);
    shapes.setColor(Color.BLUE);
    shapes.rect(0, 0, 840, 360);
    shapes.setColor(Color.RED);
    shapes.rect(0, 0, 720, 360);
    shapes.setColor(Color.LIGHT_GRAY);
    shapes.rect(0, 0, 640, 360);
    shapes.setColor(Color.WHITE);
    shapes.rect(0, 0, 100, 100);
    shapes.setColor(Color.GREEN);
    shapes.rect(0, 0, 2, viewport.getWorldHeight());
    shapes.rect(0, viewport.getWorldHeight() - 2, viewport.getWorldWidth(), viewport.getWorldHeight());
    shapes.rect(viewport.getWorldWidth() - 2, 0, 2, viewport.getWorldHeight());
    shapes.rect(0, 0, viewport.getWorldWidth(), 2);
    shapes.end();
  }

  super.render();
  cursor.act(Gdx.graphics.getDeltaTime());
  cursor.render(batch);

  Batch b = batch;
  b.setProjectionMatrix(BATCH_RESET);
  b.begin(); {
    batch.setShader(null);
    if (!Riiablo.assets.update(8)) { // TODO: (1 / 60f) - delta  --  remainder of frame time
      drawLoading(b);
    }

    if (drawFpsMethod > 0 || forceDrawFps) {
      drawFps(b);
    }

    console.render(b);
  } b.end();
}