Java Code Examples for com.badlogic.gdx.graphics.glutils.ShapeRenderer#end()

The following examples show how to use com.badlogic.gdx.graphics.glutils.ShapeRenderer#end() . 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: IBLBuilder.java    From gdx-gltf with Apache License 2.0 6 votes vote down vote up
private void render(CubemapSide side, ShapeRenderer shapes, ShaderProgram shader, float strength, float exponent){
	shader.begin();
	shader.setUniformf("u_exponent", exponent);
	shader.setUniformf("u_ambient", color.r, color.g, color.b, 0f);
	shader.setUniformf("u_diffuse", color.r, color.g, color.b, strength);

	localDir.set(side.direction);
	localUp.set(side.up);
	
	// XXX patch
	if(side == CubemapSide.NegativeX || side == CubemapSide.PositiveX){
		localDir.x = -localDir.x;
	}
		
	matrix.setToLookAt(localDir, localUp).tra();
	localSunDir.set(direction).scl(-1, -1, 1).mul(matrix); // XXX patch again
	
	shader.setUniformf("u_direction", localSunDir);
	
	shapes.begin(ShapeType.Filled);
	shapes.rect(0, 0, 1, 1);
	shapes.end();
}
 
Example 2
Source File: Scene2dRaycastObstacleAvoidanceTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
private void renderBox (ShapeRenderer shapeRenderer, Body body, float halfWidth, float halfHeight) {
	// get the bodies center and angle in world coordinates
	Vector2 pos = body.getWorldCenter();
	float angle = body.getAngle();

	// set the translation and rotation matrix
	transform.setToTranslation(pos.x, pos.y, 0);
	transform.rotate(0, 0, 1, (float)Math.toDegrees(angle));

	// render the box
	shapeRenderer.begin(ShapeType.Line);
	shapeRenderer.setTransformMatrix(transform);
	shapeRenderer.setColor(1, 1, 1, 1);
	shapeRenderer.rect(-halfWidth, -halfHeight, halfWidth * 2, halfHeight * 2);
	shapeRenderer.end();
}
 
Example 3
Source File: Box2dSteeringTest.java    From gdx-ai with Apache License 2.0 6 votes vote down vote up
protected void renderBox (ShapeRenderer shapeRenderer, Body body, float halfWidth, float halfHeight) {
	// get the bodies center and angle in world coordinates
	Vector2 pos = body.getWorldCenter();
	float angle = body.getAngle();

	// set the translation and rotation matrix
	transform.setToTranslation(Box2dSteeringTest.metersToPixels(pos.x), Box2dSteeringTest.metersToPixels(pos.y), 0);
	transform.rotate(0, 0, 1, angle * MathUtils.radiansToDegrees);

	// render the box
	shapeRenderer.begin(ShapeType.Line);
	shapeRenderer.setTransformMatrix(transform);
	shapeRenderer.setColor(1, 1, 1, 1);
	shapeRenderer.rect(-halfWidth, -halfHeight, halfWidth * 2, halfHeight * 2);
	shapeRenderer.end();
}
 
Example 4
Source File: OrthographicProjection.java    From ud405 with MIT License 6 votes vote down vote up
/**
 * This method renders a few shapes for us to try our camera on. Note that we're using a Bezier
 * curve, which is a way to draw smooth curves. For more information on Bezier curves, check
 * out: https://en.wikipedia.org/wiki/B%C3%A9zier_curve
 *
 * Also note that a line is a line is a line. No matter how much we zoom in, a line is always
 * just one pixel wide.
 */
private void renderTestScene(ShapeRenderer renderer) {
    renderer.begin(ShapeType.Filled);
    renderer.setColor(Color.GREEN);
    renderer.circle(100, 100, 90);
    renderer.setColor(Color.RED);
    renderer.rect(200, 10, 200, 200);
    renderer.setColor(Color.YELLOW);
    renderer.triangle(10, 200, 200, 200, 100, 400);
    renderer.end();
    renderer.begin(ShapeType.Line);

    renderer.setColor(Color.CYAN);

    // Here's another shape ShapeRenderer
    renderer.curve(
            210, 210,
            400, 210,
            210, 400,
            400, 300,
            20);
    renderer.end();
}
 
Example 5
Source File: DemoCamera.java    From ud405 with MIT License 6 votes vote down vote up
/**
 * Renders a blue rectangle showing the field of view of the closeup camera
 */
public void render(ShapeRenderer renderer) {
    if (!inCloseupMode) {
        // Figure out the location of the camera corners in the world
        Vector2 bottomLeft = myUnproject(closeupCamera, 0, closeupCamera.viewportHeight);
        Vector2 bottomRight = myUnproject(closeupCamera, closeupCamera.viewportWidth, closeupCamera.viewportHeight);
        Vector2 topRight = myUnproject(closeupCamera, closeupCamera.viewportWidth, 0);
        Vector2 topLeft = myUnproject(closeupCamera, 0, 0);

        // Draw a rectangle showing the closeup camera's field of view
        renderer.begin(ShapeType.Line);
        renderer.setColor(Color.BLUE);
        float[] poly = {bottomLeft.x, bottomLeft.y,
                bottomRight.x, bottomRight.y,
                topRight.x, topRight.y,
                topLeft.x, topLeft.y
        };
        renderer.set(ShapeType.Line);
        renderer.polygon(poly);
        renderer.end();
    }
}
 
Example 6
Source File: Animation.java    From riiablo with Apache License 2.0 6 votes vote down vote up
protected void drawDebug(ShapeRenderer shapeRenderer, int d, int f, float x, float y) {
  boolean reset = !shapeRenderer.isDrawing();
  if (reset) {
    shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
  } else {
    shapeRenderer.set(ShapeRenderer.ShapeType.Line);
  }

  shapeRenderer.setColor(Color.RED);
  shapeRenderer.line(x, y, x + 40, y);
  shapeRenderer.setColor(Color.GREEN);
  shapeRenderer.line(x, y, x, y + 20);
  shapeRenderer.setColor(Color.BLUE);
  shapeRenderer.line(x, y, x + 20, y - 10);

  BBox box = dc.getBox(d, f);
  shapeRenderer.setColor(DEBUG_COLOR);
  shapeRenderer.rect(x + box.xMin, y - box.yMax, box.width, box.height);
  if (reset) shapeRenderer.end();
}
 
Example 7
Source File: Cursor.java    From riiablo with Apache License 2.0 6 votes vote down vote up
public void render(PaletteIndexedBatch batch) {
  if (dc != null) {
    BBox box = dc.getBox();
    coords.set(Gdx.input.getX(), Gdx.input.getY());
    Riiablo.extendViewport.unproject(coords);
    coords.sub(box.width / 2f, box.height / 2f);

    batch.begin();
    batch.setColormap(transform, transformColor);
    if (item.isEthereal()) batch.setAlpha(Item.ETHEREAL_ALPHA);
    batch.draw(dc.getTexture(), coords.x, coords.y);
    if (item.isEthereal()) batch.resetColor();
    batch.resetColormap();
    batch.end();

    if (DEBUG_ITEM_BOUNDS) {
      ShapeRenderer shapes = Riiablo.shapes;
      shapes.setProjectionMatrix(Riiablo.extendViewport.getCamera().combined);
      shapes.begin(ShapeRenderer.ShapeType.Line);
      shapes.setColor(Color.GREEN);
      shapes.rect(coords.x, coords.y, box.width, box.height);
      shapes.end();
    }
  }
}
 
Example 8
Source File: Animation.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void drawDebug(ShapeRenderer shapes, float x, float y) {
  if (DEBUG_MODE == 0) {
    return;
  } else if (DEBUG_MODE == 1 || cof == null) {
    boolean reset = !shapes.isDrawing();
    if (reset) {
      shapes.begin(ShapeRenderer.ShapeType.Line);
    } else {
      shapes.set(ShapeRenderer.ShapeType.Line);
    }

    shapes.setColor(Color.RED);
    shapes.line(x, y, x + 50, y);
    shapes.setColor(Color.GREEN);
    shapes.line(x, y, x, y + 50);
    shapes.setColor(Color.BLUE);
    shapes.line(x, y, x + 15, y - 20);
    shapes.setColor(Color.GREEN);
    shapes.rect(x + box.xMin, y - box.yMax, box.width, box.height);
    if (reset) shapes.end();
  } else if (DEBUG_MODE == 2 && frame < numFrames) {
    int d = DC.Direction.toReadDir(direction, cof.getNumDirections());
    int f = frame;
    for (int l = 0; l < cof.getNumLayers(); l++) {
      int component = cof.getLayerOrder(d, f, l);
      Layer layer = layers[component];
      if (layer != null) layer.drawDebug(shapes, d, f, x, y);
    }
  }
}
 
Example 9
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 10
Source File: Rain.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@Override public void draw(Batch batch, float parentAlpha) {
    validate();
    batch.end();
    Gdx.gl.glClearColor(0, 0, 0, 0);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
    ShapeRenderer renderer = Config.shapeRenderer;
    renderer.setProjectionMatrix(batch.getProjectionMatrix());
    renderer.setTransformMatrix(batch.getTransformMatrix());

    renderer.begin(ShapeRenderer.ShapeType.Filled);
    renderer.setColor(style.color.r, style.color.g, style.color.b, style.color.a * parentAlpha);
    float usedWidth = getWidth() - style.pad;
    int count = (int) (usedWidth / (style.dropWidth + style.pad));
    if (count == 0)
        return;
    float step = usedWidth / ((float) count);
    float x = style.pad;
    for (int i = 0, n = rows.size; i < n; i++) {
        Row row = rows.get(i);
        drawRow(x, row);
        x += step;
    }
    renderer.end();
    Gdx.gl.glDisable(GL20.GL_BLEND);
    batch.begin();
}
 
Example 11
Source File: Level.java    From ud406 with MIT License 5 votes vote down vote up
public void render(SpriteBatch batch, ShapeRenderer renderer) {

        renderer.begin(ShapeType.Filled);
        // TODO: Render all platforms in the platform array

        renderer.end();

        batch.begin();
        gigaGal.render(batch);
        batch.end();
    }
 
Example 12
Source File: Level.java    From ud406 with MIT License 5 votes vote down vote up
public void render(SpriteBatch batch, ShapeRenderer renderer) {

        renderer.begin(ShapeType.Filled);
        // TODO: Render all platforms in the platform array
        for (Platform platform : platforms) {
            platform.render(renderer);
        }
        renderer.end();

        batch.begin();
        gigaGal.render(batch);
        batch.end();
    }
 
Example 13
Source File: EntityStage.java    From Norii with Apache License 2.0 5 votes vote down vote up
public void drawEntitiesDebug() {
	final Array<Actor> actors = getActors();
	final ShapeRenderer debugRenderer = new ShapeRenderer();
	debugRenderer.setProjectionMatrix(getCamera().combined);
	debugRenderer.setColor(Color.RED);
	debugRenderer.begin(ShapeType.Line);
	for (final Actor actor : actors) {
		actor.debug();
		actor.drawDebug(debugRenderer);
	}
	debugRenderer.end();
}
 
Example 14
Source File: RenderSystem.java    From riiablo with Apache License 2.0 4 votes vote down vote up
private void drawDebugSpecial(ShapeRenderer shapes) {
  for (int i = Map.WALL_OFFSET, x, y; i < Map.WALL_OFFSET + Map.MAX_WALLS; i++) {
    int startX2 = startX;
    int startY2 = startY;
    float startPx2 = startPx;
    float startPy2 = startPy;
    for (y = 0; y < viewBuffer.length; y++) {
      int tx = startX2;
      int ty = startY2;
      int stx = tx * Tile.SUBTILE_SIZE;
      int sty = ty * Tile.SUBTILE_SIZE;
      float px = startPx2;
      float py = startPy2;
      int size = viewBuffer[y];
      for (x = 0; x < size; x++) {
        Map.Zone zone = map.getZone(stx, sty);
        if (zone != null) {
          DS1.Cell cell = zone.getCell(i, tx, ty);
          if (cell != null) {
            if (Map.ID.POPPADS.contains(cell.id)) {
              shapes.setColor(Map.ID.getColor(cell));
              Map.Preset preset = zone.getGrid(tx, ty);
              Map.Preset.PopPad popPad = preset.popPads.get(cell.id);
              if (popPad.startX == zone.getGridX(tx) && popPad.startY == zone.getGridY(ty)) {
                int width  = popPad.endX - popPad.startX;
                int height = popPad.endY - popPad.startY;
                iso.getPixOffset(tmpVec2);
                float offsetX = tmpVec2.x;
                float offsetY = tmpVec2.y;
                iso.toScreen(tmpVec2.set(stx, sty));
                float topLeftX = tmpVec2.x - offsetX;
                float topLeftY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(width, 0));
                float topRightX = tmpVec2.x - offsetX;
                float topRightY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(0, height));
                float bottomLeftX = tmpVec2.x - offsetX;
                float bottomLeftY = tmpVec2.y - offsetY;
                iso.toScreen(tmpVec2.set(stx, sty).add(width, height));
                float bottomRightX = tmpVec2.x - offsetX;
                float bottomRightY = tmpVec2.y - offsetY;
                shapes.line(topLeftX, topLeftY, topRightX, topRightY);
                shapes.line(topRightX, topRightY, bottomRightX, bottomRightY);
                shapes.line(bottomRightX, bottomRightY, bottomLeftX, bottomLeftY);
                shapes.line(bottomLeftX, bottomLeftY, topLeftX, topLeftY);
              }
            } else {
              shapes.setColor(Color.WHITE);
              DebugUtils.drawDiamond2(shapes, px, py, Tile.WIDTH, Tile.HEIGHT);
            }
            shapes.end();

            batch.begin();
            batch.setShader(null);
            BitmapFont font = Riiablo.fonts.consolas12;
            String str = String.format("%s%n%08x", Map.ID.getName(cell.id), cell.value);
            GlyphLayout layout = new GlyphLayout(font, str, 0, str.length(), font.getColor(), 0, Align.center, false, null);
            font.draw(batch, layout,
                px + Tile.WIDTH50,
                py + Tile.HEIGHT50 + font.getLineHeight() / 4);
            batch.end();
            batch.setShader(Riiablo.shader);

            shapes.begin(ShapeRenderer.ShapeType.Line);
          }
        }

        tx++;
        stx += Tile.SUBTILE_SIZE;
        px += Tile.WIDTH50;
        py -= Tile.HEIGHT50;
      }

      startY2++;
      if (y >= tilesX - 1) {
        startX2++;
        startPy2 -= Tile.HEIGHT;
      } else {
        startX2--;
        startPx2 -= Tile.WIDTH;
      }
    }
  }
}
 
Example 15
Source File: Entity.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public void drawDebugStatus(PaletteIndexedBatch batch, ShapeRenderer shapes) {
  float x = screen.x;
  float y = screen.y;
  if (animation != null && isSelectable()) animation.drawDebug(shapes, x, y);

  shapes.setColor(Color.WHITE);
  DebugUtils.drawDiamond(shapes, x, y, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);
  //shapes.ellipse(x - Tile.SUBTILE_WIDTH50, y - Tile.SUBTILE_HEIGHT50, Tile.SUBTILE_WIDTH, Tile.SUBTILE_HEIGHT);

  final float R = 32;
  shapes.setColor(Color.RED);
  shapes.line(x, y, x + MathUtils.cos(angle) * R, y + MathUtils.sin(angle) * R);

  if (animation != null) {
    int numDirs = animation.getNumDirections();
    float rounded = Direction.snapToDirection(angle, numDirs);
    shapes.setColor(Color.GREEN);
    shapes.line(x, y, x + MathUtils.cos(rounded) * R * 0.5f, y + MathUtils.sin(rounded) * R * 0.5f);
  }

  shapes.end();
  batch.begin();
  batch.setShader(null);
  StringBuilder builder = new StringBuilder(64)
      .append(classname).append('\n')
      .append(token).append(' ').append(type.MODE[mode]).append(' ').append(WCLASS[wclass]).append('\n');
  if (animation != null) {
    builder
        .append(StringUtils.leftPad(Integer.toString(animation.getFrame()), 2))
        .append('/')
        .append(StringUtils.leftPad(Integer.toString(animation.getNumFramesPerDir() - 1), 2))
        .append(' ')
        .append(animation.getFrameDelta())
        .append('\n');
  }
  appendToStatus(builder);
  GlyphLayout layout = Riiablo.fonts.consolas12.draw(batch, builder.toString(), x, y - Tile.SUBTILE_HEIGHT50, 0, Align.center, false);
  Pools.free(layout);
  batch.end();
  batch.setShader(Riiablo.shader);
  shapes.begin(ShapeRenderer.ShapeType.Line);
}
 
Example 16
Source File: Scene.java    From bladecoder-adventure-engine with Apache License 2.0 4 votes vote down vote up
public void drawBBoxLines(ShapeRenderer renderer) {
	// renderer.begin(ShapeType.Rectangle);
	renderer.begin(ShapeType.Line);

	for (BaseActor a : actors.values()) {
		Polygon p = a.getBBox();

		if (p == null) {
			EngineLogger.error("ERROR DRAWING BBOX FOR: " + a.getId());
		}

		if (a instanceof ObstacleActor) {
			renderer.setColor(OBSTACLE_COLOR);
			renderer.polygon(p.getTransformedVertices());
		} else if (a instanceof AnchorActor) {
			renderer.setColor(Scene.ANCHOR_COLOR);
			renderer.line(p.getX() - Scene.ANCHOR_RADIUS, p.getY(), p.getX() + Scene.ANCHOR_RADIUS, p.getY());
			renderer.line(p.getX(), p.getY() - Scene.ANCHOR_RADIUS, p.getX(), p.getY() + Scene.ANCHOR_RADIUS);
		} else {
			renderer.setColor(ACTOR_BBOX_COLOR);
			renderer.polygon(p.getTransformedVertices());
		}

		// Rectangle r = a.getBBox().getBoundingRectangle();
		// renderer.rect(r.getX(), r.getY(), r.getWidth(), r.getHeight());
	}

	if (walkZone != null) {
		renderer.setColor(WALKZONE_COLOR);
		renderer.polygon(polygonalNavGraph.getWalkZone().getTransformedVertices());

		// DRAW LINEs OF SIGHT
		renderer.setColor(Color.WHITE);
		ArrayList<NavNodePolygonal> nodes = polygonalNavGraph.getGraphNodes();
		for (NavNodePolygonal n : nodes) {
			for (NavNodePolygonal n2 : n.neighbors) {
				renderer.line(n.x, n.y, n2.x, n2.y);
			}
		}
	}

	renderer.end();
}
 
Example 17
Source File: Snake.java    From super-snake with MIT License 4 votes vote down vote up
private void draw_line(ShapeRenderer shapeRenderer, float x0, float y0, float x1, float y1) {
    shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
    shapeRenderer.setColor(color);
    shapeRenderer.rectLine(x0, y0, x1, y1, size);
    shapeRenderer.end();
}