ShapeRenderer API changes

I just committed some changes to the repository that update the ShapeRenderer API. Yes, it’ll break you current code but the fixes will be trivial.

We’ve changed from having a large number of ShapeTypes (Rectangle, FilledRectangle, etc.) to having 3 shape types reflecting the underlying OpenGl primitives used: ShapeType.Point, ShapeType.Line and ShapeType.Filled.

This allows us to batch various shapes that previously would’ve caused a new batch. For example:

Previously that would’ve required 4 batches and can now be done in one 🙂

There are a few exceptions to note: Line, Curve, Polygon & Box only work with ShapeType.Line. Point plotting only works with ShapeType.Point. The rest works for both ShapeType.Line & ShapeType.Filled. If you make a mistake here, it’ll throw an exception.

Sorry for breaking the API but I figured it was worth it for making it easier & faster to use ShapeRenderer.

9 thoughts on “ShapeRenderer API changes

  1. The new system looks awesome, however, I can’t get it to play nice. I can draw lines and points fine, but triangles, circles, rects and polygons all throw an ArrayIndexOutOfBoundsException at ….glutils.ImmediateModeRenderer20.color( and at ….glutils.ShapeRenderer.rect(
    Am I doing something wrong? (at this point I’m just beginning a filled shape, setting a color, drawing a rect and ending the shape, and no matter what I try, the application hangs at the rect-call).

  2. @shinmai: I can’t reproduce your problem. Can you file an issue on the issue-tracker with the exact steps to reproduce this? Preferably with a sample project.

  3. I would, but after updating to the latest nightly last night, I tried again today (having already hacked what I was trying to achieve with sprites and tinting) and now everything works as expected. I’d revert to my old code but I’m between development machines and didn’t have source controle set up at the time 🙁

    I can try to check out an older revision and see if I can reproduce, all I did was: create new libgdx project with libgdx-setup, change android projec to use GL2.0, create a shaperenderer object in create() and in render() begin a filled shape, set color to Color.RED, draw rect, end shape. Running the above on all occasions I tried between Feb 4th and last night would result in an ArrayIndexOutOfBound, but now works perfectly.

    Haven’t had time to look into this properly, but I’m extremely happy everything is working. Thanks for your hard work, the new API is absolutely awesome.

  4. @shinmai: good to hear it’s working out for you! If you run into any problems with it again please do let us know, it’s much appreciated 🙂

  5. Ok I choose the bad day to update my project with the last GDX version 😉


    shapeRenderer.filledRect(0, 0, 1280, 752);

    Changed to:

    shapeRenderer.rect(0, 0, 1280, 752);

    got an error:

    Exception in thread “LWJGL Application” com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoSuchFieldError: Filled
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$
    Caused by: java.lang.NoSuchFieldError: Filled

  6. This new update is cool but could you please update the new Box2D version. I’m having trouble with several of these which I want to implement into a game I’m making. It would be most appreciated.

Leave a Reply

Your email address will not be published.