By default a 2D orthographic projection with the origin in the lower left corner is used and units are specified in screen
pixels. This can be changed by configuring the projection matrix, usually using the Camera#combined matrix. If the
screen resolution changes, the projection matrix may need to be updated.
Shapes are rendered in batches to increase performance. Standard usage pattern looks as follows:
camera.update();
shapeRenderer.setProjectionMatrix(camera.combined);
shapeRenderer.begin(ShapeType.Line);
shapeRenderer.setColor(1, 1, 0, 1);
shapeRenderer.line(x, y, x2, y2);
shapeRenderer.rect(x, y, width, height);
shapeRenderer.circle(x, y, radius);
shapeRenderer.end();
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(0, 1, 0, 1);
shapeRenderer.rect(x, y, width, height);
shapeRenderer.circle(x, y, radius);
shapeRenderer.end();
ShapeRenderer has a second matrix called the transformation matrix which is used to rotate, scale and translate shapes in a
more flexible manner. The following example shows how to rotate a rectangle around its center using the z-axis as the rotation
axis and placing it's center at (20, 12, 2):
shapeRenderer.begin(ShapeType.Line); shapeRenderer.identity(); shapeRenderer.translate(20, 12, 2); shapeRenderer.rotate(0, 0, 1, 90); shapeRenderer.rect(-width / 2, -height / 2, width, height); shapeRenderer.end();Matrix operations all use postmultiplication and work just like glTranslate, glScale and glRotate. The last transformation specified will be the first that is applied to a shape (rotate then translate in the above example).
The projection and transformation matrices are a state of the ShapeRenderer, just like the color, and will be applied to all shapes until they are changed.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | ShapeRenderer.
Shape types to be used with |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private final Color | |
| private final Matrix4 | |
| private float | |
| private boolean | |
| private final Matrix4 | |
| private final ImmediateModeRenderer | |
| private ShapeRenderer. | |
| private final Vector2 | |
| private final Matrix4 |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | arc(float x, float y, float radius, float start, float degrees)
Calls |
| public void | arc(float x, float y, float radius, float start, float degrees, int segments)
Draws an arc using |
| public void | |
| public void | |
| public void | box(float x, float y, float z, float width, float height, float depth)
Draws a cube using |
| protected final void | check(ShapeRenderer.
usually ShapeType.Line preferred,usually ShapeType.Filled. May be null. other,vertices count of geometric figure you want to draw newVertices)Checks whether the correct ShapeType was set. |
| public void | circle(float x, float y, float radius)
Calls |
| public void | circle(float x, float y, float radius, int segments)
Draws a circle using |
| public void | cone(float x, float y, float z, float radius, float height)
Calls |
| public void | cone(float x, float y, float z, float radius, float height, int segments)
Draws a cone using |
| public void | curve(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, int segments)
Draws a curve using |
| public void | dispose()
Implements com. Releases all resources of this object. |
| public void | ellipse(float x, float y, float width, float height)
Calls |
| public void | ellipse(float x, float y, float width, float height, int segments)
Draws an ellipse using |
| public void | ellipse(float x, float y, float width, float height, float rotation)
Calls |
| public void | ellipse(float x, float y, float width, float height, float rotation, int segments)
Draws an ellipse using |
| public void | |
| public void | |
| public Color | |
| public ShapeRenderer. | |
| public Matrix4 | |
| public ImmediateModeRenderer | |
| public Matrix4 | |
| public void | |
| public boolean | |
| public final void | line(float x, float y, float z, float x2, float y2, float z2)
Draws a line using |
| public final void | |
| public final void | |
| public final void | |
| public final void | |
| public void | line(float x, float y, float z, float x2, float y2, float z2, Color c1, Color c2)
Draws a line using |
| public void | point(float x, float y, float z)
Draws a point using |
| public void | polygon(float[] vertices, int offset, int count)
Draws a polygon in the x/y plane using |
| public void | |
| public void | polyline(float[] vertices, int offset, int count)
Draws a polyline in the x/y plane using |
| public void | |
| public void | rect(float x, float y, float width, float height)
Draws a rectangle in the x/y plane using |
| public void | rect(float x, float y, float width, float height, Color
The color at (x, y). col1, Color The color at (x + width, y). col2, Color The color at (x + width, y + height). col3, Color The color at (x, y + height). col4)Draws a rectangle in the x/y plane using |
| public void | rect(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float degrees)
Draws a rectangle in the x/y plane using |
| public void | rect(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float degrees, Color
The color at (x, y) col1, Color The color at (x + width, y) col2, Color The color at (x + width, y + height) col3, Color The color at (x, y + height) col4)Draws a rectangle in the x/y plane using |
| public void | rectLine(float x1, float y1, float x2, float y2, float width)
Draws a line using a rotated rectangle, where with one edge is centered at x1, y1 and the opposite edge centered at x2, y2. |
| public void | |
| public void | |
| public void | rotate(float axisX, float axisY, float axisZ, float degrees)
Multiplies the current transformation matrix by a rotation matrix. |
| public void | scale(float scaleX, float scaleY, float scaleZ)
Multiplies the current transformation matrix by a scale matrix. |
| public void | |
| public void | setAutoShapeType(boolean autoShapeType)
If true, when drawing a shape cannot be performed with the current shape type, the batch is flushed and the shape type is changed automatically. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | translate(float x, float y, float z)
Multiplies the current transformation matrix by a translation matrix. |
| public void | triangle(float x1, float y1, float x2, float y2, float x3, float y3)
Draws a triangle in x/y plane using |
| public void | triangle(float x1, float y1, float x2, float y2, float x3, float y3, Color col1, Color col2, Color col3)
Draws a triangle in x/y plane with colored corners using |
| public void | |
| public void | |
| public void |
| autoShapeType | back to summary |
|---|---|
| private boolean autoShapeType | |
| color | back to summary |
|---|---|
| private final Color color | |
| combinedMatrix | back to summary |
|---|---|
| private final Matrix4 combinedMatrix | |
| defaultRectLineWidth | back to summary |
|---|---|
| private float defaultRectLineWidth | |
| matrixDirty | back to summary |
|---|---|
| private boolean matrixDirty | |
| projectionMatrix | back to summary |
|---|---|
| private final Matrix4 projectionMatrix | |
| renderer | back to summary |
|---|---|
| private final ImmediateModeRenderer renderer | |
| shapeType | back to summary |
|---|---|
| private ShapeRenderer. | |
| tmp | back to summary |
|---|---|
| private final Vector2 tmp | |
| transformMatrix | back to summary |
|---|---|
| private final Matrix4 transformMatrix | |
| ShapeRenderer | back to summary |
|---|---|
| public ShapeRenderer() | |
| ShapeRenderer | back to summary |
|---|---|
| public ShapeRenderer(int maxVertices) | |
| ShapeRenderer | back to summary |
|---|---|
| public ShapeRenderer(int maxVertices, ShaderProgram defaultShader) | |
| arc | back to summary |
|---|---|
| public void arc(float x, float y, float radius, float start, float degrees) Calls | |
| arc | back to summary |
|---|---|
| public void arc(float x, float y, float radius, float start, float degrees, int segments) Draws an arc using | |
| begin | back to summary |
|---|---|
| public void begin() Begins a new batch without specifying a shape type.
| |
| begin | back to summary |
|---|---|
| public void begin(ShapeRenderer. Starts a new batch of shapes. Shapes drawn within the batch will attempt to use the type specified. The call to this method
must be paired with a call to
| |
| box | back to summary |
|---|---|
| public void box(float x, float y, float z, float width, float height, float depth) Draws a cube using | |
| check | back to summary |
|---|---|
| protected final void check(ShapeRenderer. Checks whether the correct ShapeType was set. If not and autoShapeType is enabled, it flushes the batch and changes the shape type. The batch is also flushed, when the matrix has been changed or not enough vertices remain.
| |
| circle | back to summary |
|---|---|
| public void circle(float x, float y, float radius) Calls | |
| circle | back to summary |
|---|---|
| public void circle(float x, float y, float radius, int segments) Draws a circle using | |
| cone | back to summary |
|---|---|
| public void cone(float x, float y, float z, float radius, float height) Calls | |
| cone | back to summary |
|---|---|
| public void cone(float x, float y, float z, float radius, float height, int segments) Draws a cone using | |
| curve | back to summary |
|---|---|
| public void curve(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2, int segments) Draws a curve using | |
| dispose | back to summary |
|---|---|
| public void dispose() Implements com. Doc from com. Releases all resources of this object. | |
| ellipse | back to summary |
|---|---|
| public void ellipse(float x, float y, float width, float height) Calls | |
| ellipse | back to summary |
|---|---|
| public void ellipse(float x, float y, float width, float height, int segments) Draws an ellipse using | |
| ellipse | back to summary |
|---|---|
| public void ellipse(float x, float y, float width, float height, float rotation) Calls | |
| ellipse | back to summary |
|---|---|
| public void ellipse(float x, float y, float width, float height, float rotation, int segments) Draws an ellipse using | |
| end | back to summary |
|---|---|
| public void end() Finishes the batch of shapes and ensures they get rendered. | |
| flush | back to summary |
|---|---|
| public void flush() | |
| getColor | back to summary |
|---|---|
| public Color getColor() | |
| getCurrentType | back to summary |
|---|---|
| public ShapeRenderer. Returns the current shape type. | |
| getProjectionMatrix | back to summary |
|---|---|
| public Matrix4 getProjectionMatrix() If the matrix is modified, | |
| getRenderer | back to summary |
|---|---|
| public ImmediateModeRenderer getRenderer() | |
| getTransformMatrix | back to summary |
|---|---|
| public Matrix4 getTransformMatrix() If the matrix is modified, | |
| identity | back to summary |
|---|---|
| public void identity() Sets the transformation matrix to identity. | |
| isDrawing | back to summary |
|---|---|
public boolean isDrawing()
| |
| line | back to summary |
|---|---|
| public final void line(float x, float y, float z, float x2, float y2, float z2) Draws a line using | |
| line | back to summary |
|---|---|
| public final void line(Vector3 v0, Vector3 v1) | |
| line | back to summary |
|---|---|
| public final void line(float x, float y, float x2, float y2) | |
| line | back to summary |
|---|---|
| public final void line(Vector2 v0, Vector2 v1) | |
| line | back to summary |
|---|---|
| public final void line(float x, float y, float x2, float y2, Color c1, Color c2) | |
| line | back to summary |
|---|---|
| public void line(float x, float y, float z, float x2, float y2, float z2, Color c1, Color c2) Draws a line using | |
| point | back to summary |
|---|---|
| public void point(float x, float y, float z) Draws a point using | |
| polygon | back to summary |
|---|---|
| public void polygon(float[] vertices, int offset, int count) Draws a polygon in the x/y plane using | |
| polygon | back to summary |
|---|---|
public void polygon(float[] vertices)
| |
| polyline | back to summary |
|---|---|
| public void polyline(float[] vertices, int offset, int count) Draws a polyline in the x/y plane using | |
| polyline | back to summary |
|---|---|
public void polyline(float[] vertices)
| |
| rect | back to summary |
|---|---|
| public void rect(float x, float y, float width, float height) Draws a rectangle in the x/y plane using | |
| rect | back to summary |
|---|---|
| public void rect(float x, float y, float width, float height, Color col1, Color col2, Color col3, Color col4) Draws a rectangle in the x/y plane using | |
| rect | back to summary |
|---|---|
| public void rect(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float degrees) Draws a rectangle in the x/y plane using | |
| rect | back to summary |
|---|---|
| public void rect(float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float degrees, Color col1, Color col2, Color col3, Color col4) Draws a rectangle in the x/y plane using | |
| rectLine | back to summary |
|---|---|
| public void rectLine(float x1, float y1, float x2, float y2, float width) Draws a line using a rotated rectangle, where with one edge is centered at x1, y1 and the opposite edge centered at x2, y2. | |
| rectLine | back to summary |
|---|---|
| public void rectLine(float x1, float y1, float x2, float y2, float width, Color c1, Color c2) Draws a line using a rotated rectangle, where with one edge is centered at x1, y1 and the opposite edge centered at x2, y2. | |
| rectLine | back to summary |
|---|---|
| public void rectLine(Vector2 p1, Vector2 p2, float width) | |
| rotate | back to summary |
|---|---|
| public void rotate(float axisX, float axisY, float axisZ, float degrees) Multiplies the current transformation matrix by a rotation matrix. | |
| scale | back to summary |
|---|---|
| public void scale(float scaleX, float scaleY, float scaleZ) Multiplies the current transformation matrix by a scale matrix. | |
| set | back to summary |
|---|---|
| public void set(ShapeRenderer. | |
| setAutoShapeType | back to summary |
|---|---|
| public void setAutoShapeType(boolean autoShapeType) If true, when drawing a shape cannot be performed with the current shape type, the batch is flushed and the shape type is changed automatically. This can increase the number of batch flushes if care is not taken to draw the same type of shapes together. Default is false. | |
| setColor | back to summary |
|---|---|
| public void setColor(Color color) Sets the color to be used by the next shapes drawn. | |
| setColor | back to summary |
|---|---|
| public void setColor(float r, float g, float b, float a) Sets the color to be used by the next shapes drawn. | |
| setProjectionMatrix | back to summary |
|---|---|
| public void setProjectionMatrix(Matrix4 matrix) Sets the projection matrix to be used for rendering. Usually this will be set to | |
| setTransformMatrix | back to summary |
|---|---|
| public void setTransformMatrix(Matrix4 matrix) | |
| translate | back to summary |
|---|---|
| public void translate(float x, float y, float z) Multiplies the current transformation matrix by a translation matrix. | |
| triangle | back to summary |
|---|---|
| public void triangle(float x1, float y1, float x2, float y2, float x3, float y3) Draws a triangle in x/y plane using | |
| triangle | back to summary |
|---|---|
| public void triangle(float x1, float y1, float x2, float y2, float x3, float y3, Color col1, Color col2, Color col3) Draws a triangle in x/y plane with colored corners using | |
| updateMatrices | back to summary |
|---|---|
| public void updateMatrices() | |
| x | back to summary |
|---|---|
| public void x(float x, float y, float size) Draws two crossed lines using | |
| x | back to summary |
|---|---|
public void x(Vector2 p, float size)
| |
begin(ShapeType).
| Modifier and Type | Field and Description |
|---|---|
| public static final ShapeRenderer. | |
| private final int | |
| public static final ShapeRenderer. | |
| public static final ShapeRenderer. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | |
| public static ShapeRenderer. | |
| public static ShapeRenderer. |
| Filled | back to summary |
|---|---|
| public static final ShapeRenderer. | |
| glType | back to summary |
|---|---|
| private final int glType | |
| Line | back to summary |
|---|---|
| public static final ShapeRenderer. | |
| Point | back to summary |
|---|---|
| public static final ShapeRenderer. | |
| ShapeType | back to summary |
|---|---|
| private ShapeType(int glType) | |
| getGlType | back to summary |
|---|---|
| public int getGlType() | |
| valueOf | back to summary |
|---|---|
| public static ShapeRenderer. | |
| values | back to summary |
|---|---|
| public static ShapeRenderer. | |