用OpenGL(和OpenGL ES)渲染SVG [英] Rendering SVG with OpenGL (and OpenGL ES)

查看:2590
本文介绍了用OpenGL(和OpenGL ES)渲染SVG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在调查使用的OpenGL和OpenGL ES SVG文件渲染矢量图形的可能性。我打算面向Windows和Android。我的理想的解决办法是有一个最小的C库生成从给定的SVG文件的多边形三角测量。这将然后生成标准的OpenGL或OpenGL ES电话,并使用显示列表或VBO优化重画。我会简单地画一个显示列表平移和旋转后绘制矢量图像,让我和其他的OpenGL调用混用这一点。

I am currently investigating the possibility of rendering vector graphics from an SVG file using OpenGL and OpenGL ES. I intend to target Windows and Android. My ideal solution would be to have a minimal C library that generates a polygon triangulation from a given SVG file. This would then generate standard OpenGL or OpenGL ES calls, and use a display list or vbo for optimization when redrawing. I would simply draw a display list to draw the vector image after translating and rotating, allowing me to mix this with other OpenGL calls.

到目前为止,我看到的建议是首先使用Qt或开罗。 - 这是不是一种选择,因为我要管理不臃肿的图书馆我自己的OpenGL上下文(在我所努力实现的范围内)。这也不是适用于Android的。

So far I see that the suggestions are to firstly use QT or Cairo. - This is not an option given that I wish to manage my own OpenGL context without bloated libraries (in the context of what I am trying to achieve). Nor is this suitable for Android.

第二选项是使用该渲染到纹理库。虽然这可能是确定的静态矢量图形,它不是一个有效的和可行的方案为游戏中缩放和旋转时有发生。

Second option is to use libraries that render to a texture. While this might be ok for static vector graphics, it's not an efficient or feasible option for games where scaling and rotations occur frequently.

第三存在使用OpenVG的的可能性。有OpenVG的规格(ShivaVG等)的一些开源实现,但我还没有找到一个库,它能够产生在运行时给定的SVG文件中的相应OpenVG的电话,我看不出如何优化这是我们不妨用一个显示列表或VBO。

Thirdly there is the possibility of using OpenVG. There are some opensource implementations of the OpenVG specification (ShivaVG etc), but I am yet to find a library that is capable of generating the appropriate OpenVG calls from a given SVG file at runtime, and I can't see how to optimize this as we might wish to with a display list or vbo.

这三种方法都有局限性。我认为最有前途的选项是使用OpenVG的实现,如果没有其他解决办法存在。所以我的问题是,是否有任何图书馆,在那里,我想要的东西,或接近我想要什么?如果没有,是否有一个很好的理由,为什么不?而且会是更好地试图从地面做这件事呢?

All three methods suffer limitations. I think the most promising option is using an OpenVG implementation if no other solution exists. So my question is, are there any libraries out there that do what I want, or close to what I want? If not, is there a good reason why not? And would it be better to attempt to do this from the ground up instead?

推荐答案

从<一个href="http://shivavg.svn.sourceforge.net/viewvc/shivavg/trunk/src/shPipeline.c?revision=14&view=markup" rel="nofollow">http://shivavg.svn.sourceforge.net/viewvc/shivavg/trunk/src/shPipeline.c?revision=14&view=markup

static void shDrawVertices(SHPath *p, GLenum mode)
{
int start = 0;
int size = 0;

/* We separate vertex arrays by contours to properly
handle the fill modes */
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, sizeof(SHVertex), p->vertices.items);

while (start < p->vertices.size) {
size = p->vertices.items[start].flags;
glDrawArrays(mode, start, size);
start += size;
}

glDisableClientState(GL_VERTEX_ARRAY);
}

所以它并使用VBO。所以,我建议让自己的SVG解析器/使用pre-做了一个,并转发呼叫ShivaVG。

So it does use a VBO. So I'd suggest making your own SVG parser / use a pre-made one, and forward the calls to ShivaVG.

您仍然有问题ShivaVG是在C(而不是Java)中,并创建OpenGL上下文(而不是opengles,如果我读了code正确)。所以,即使你使用的是Android的NDK编译它,你就必须修改code(例如,我已经看到了一些glVertex3f各地,但他们似乎并没有得到急需的......希望了最好的)。另一种选择,当然,它口code,从C到Java的。也许不是痛苦的,你可以想像。

You still have the problem that ShivaVG is in C (and not in Java) and creates an opengl context (and not opengles, if I read the code correctly). So even if you compile it using Android's NDK, you'll have to modify the code ( for instance, I've seen a few glVertex3f around, but they don't seem to be much needed... hope for the best). The other option, of course, it to port the code from C to Java. Maybe not as painful as you could imagine.

祝你好运!

这篇关于用OpenGL(和OpenGL ES)渲染SVG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆