Is there a way to incorporate vector graphics into LibGDX development?

别等时光非礼了梦想. 提交于 2019-12-18 05:54:13

问题


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 ?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/17322995/is-there-a-way-to-incorporate-vector-graphics-into-libgdx-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!