I haven't found anything in LibGDX that would work with vector graphics.
This post suggests that AGG is close as it gets, they also mentioned that it is a lot of pain.
Is there a painless alternative ?
Vector graphics are computer images created using a sequence of commands or mathematical statements that place lines and shapes in a two-dimensional or three-dimensional space. In vector graphics, a graphic artist's work, or file, is created and saved as a sequence of vector statements.
Vector-based animations, meaning computer generated 2D animations, uses the exact same techniques as traditional animation, but benefits from the lack of physical objects needed to make traditional 2D animations, as well as the ability to use computer interpolation to same time.
There are various software available to create, design, or edit a vector image. Some of them are Adobe illustrator, CorelDRAW Vector Graphics Software, Vectr, Affinity Designer, Sketch, Vecteezy, Graphic, and so on.
Vector graphics are stored as a list of attributes. Rather than storing the data for each pixel of an image, the computer will generate an object by looking at its attributes. The attributes are shown in bold, their values come immediately after the = sign.
There does not seem to be any painless support for vector graphics in Libgdx at this point (mid-2013). First, for vector graphics generally that means SVG in practice.
Part of the problem with a "generic" SVG solution is that getting it to work with all the various corner cases seems to be an issue. However, if you are just trying to render your own SVG objects, you may have a simpler subset of SVG to deal with and hacking something up may work for you (even if its not generic enough for everybody).
Additionally, if you're willing to use bitmaps as an intermediary (you don't need to render the vector graphics directly to the screen), you just need to find a Java-based SVG parser and rasterizer (vs. one that uses a Libgdx or LWJGL backend).
See Using SVG files with libgdx. The suggestion here is to use the Libgdx ShapeRenderer
for simple "scalable" graphics. Its no SVG, but its might be reasonable for your use case.
Google searches turned up this GPL'd Java SVG renderer that uses an AWT backend. This code looks simple enough that it could be adapted to use Libgdx rendering. But, given how simple it is, its not clear how much of SVG is actually supports (or if it even works at all).
The Apache Batik project is a generic Java SVG parser and renderer. It looks enormous. You may be able to get it to render SVG into .png format (and then convert those into Libgdx Pixmaps). (I don't have any experience with this.)
There is a (dead?) libgdx SVG extension project but it looks like only the most basic SVG parsing has been completed.
I'm still learning LibGDX too and am about to face some similiar problems like you; Rendering 2D models in the Orthographic View.
LibGDX works with OpenGL ES for graphics and also supports importing models which are created with a plugin for Blender 3D. I haven't tried this yet, but here is a solution for doing so:
Importing Models from Blender
Processing code
I guess that A solution to solve this would be to model your scalable graphics in Blender 3D. If you are using SVG files, then Blender 3D is able to import those files, so you could use Blender 3D as the first touchdown.
ADD: I now managed to do it. There is a little twist though: The method with the python script is outdated. In the comments on the page to the first link above, there is a link to xoppa's tutorials. It's described there how to export models with the FBX converter tool. I made a 2D plane shape facing the front view in Blender 3D. Exported it to FBX and used the converter tool to make a G3DB file. Using LibGdx's G3dModelLoader method as described in xoppa's tutorials, you can now draw it in your view with a ModelBatch. Make your Orthographic camera look at 0,0,0 (or whatever fits your needs) and go a little back on the z axis - else you will not be able to see it. Since it's an Orthographic camera it doesen't matter how far, but somehow 0,0,1 would make some sort of sense :) Remember also to clear the GL_DEPTH_BUFFER_BIT now for each frame in your render.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With