在OpenGL中渲染矢量图形? [英] Rendering Vector Graphics in OpenGL?

查看:486
本文介绍了在OpenGL中渲染矢量图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以加载矢量图形文件,然后使用OpenGL渲染它?这是一个模糊的问题,因为我对矢量图形的文件格式了解不多.我知道SVG.

Is there a way to load a vector graphics file and then render it using OpenGL? This is a vague question as I don't know much about file formats for vector graphics. I know of SVG, though.

将其转换为栅格并没有太大帮助,因为我想实时放大对象.

Turning it to raster isn't really helpful as I want to do real time zooming in on the objects.

推荐答案

让我详细介绍Greg的答案.

Let me expand on Greg's answer.

Qt确实具有SVG渲染器类QSvgRenderer.另外,您可以在任何"QPaintDevice"上完成您在Qt中所做的任何绘制,我们对以下绘画设备"感兴趣:

It's true that Qt has a SVG renderer class, QSvgRenderer. Also, any drawing that you do in Qt can be done on any "QPaintDevice", where we're interested in the following "paint devices":

  • 一个Qt小部件;
  • 尤其是基于GL的Qt小部件(QGLWidget);
  • Qt图片

因此,如果您决定使用Qt,则可以选择:

So, if you decide to use Qt, your options are:

  1. 停止使用当前设置窗口(和GL上下文)的方法,并开始使用QGLWidget进行所有渲染,包括 SVG渲染.根据您的需要,这可能是一个很小的更改. QGLWidget的功能并没有特别的限制.
  2. 使用QSvgRenderer渲染到QImage,然后将该QImage中的数据放入GL纹理中(如通常那样),并以任意方式渲染(例如,将其渲染为矩形GL_QUAD).可能比其他方法的性能更差,但对代码的更改最少.
  1. Stop using your current method of setting up the window (and GL context), and start using QGLWidget for all your rendering, including the SVG rendering. This might be a pretty small change, depending on your needs. QGLWidget isn't particularly limiting in its capabilities.
  2. Use QSvgRenderer to render to a QImage, then put the data from that QImage into a GL texture (as you normally would), and render it any way you want (e.g. into a rectangular GL_QUAD). Might have worse performance than the other method but requires the least change to your code.

想知道QGLWidget到底做什么?好吧,当您向QGLWidget发出Qt渲染命令时,它们会为您转换为GL调用.当SVG渲染器发出渲染命令时,也会发生这种情况.因此,最后,您的SVG将最终通过一堆GL基本体(线,多边形等)进行渲染.

Wondering what QGLWidget does exactly? Well, when you issue Qt rendering commands to a QGLWidget, they're translated to GL calls for you. And this also happens when the rendering commands are issued by the SVG renderer. So in the end, your SVG is going to end up being rendered via a bunch of GL primitives (lines, polygons, etc).

这有一个缺点.不同的视频卡在实现OpenGL方面略有不同,并且Qt不能(也不能)解决所有这些差异.因此,例如,如果您的用户有一个便宜的板载Intel视频卡,那么他的视频卡不支持OpenGL抗锯齿,这意味着如果直接将其渲染到QGLWidget,您的SVG也会显得混叠(锯齿状).通过QImage可以避免此类问题.

This has a disadvantage. Different videocards implement OpenGL slightly differently, and Qt does not (and can not) account for all those differences. So, for example, if your user has a cheap on-board Intel videocard, then his videocard doesn't support OpenGL antialiasing, and this means your SVG will also look aliased (jaggy), if you render it directly to a QGLWidget. Going through a QImage avoids such problems.

在实时缩放时,您也可以使用QImage方法.这仅取决于您需要多快.您可能需要仔细的优化,例如重用相同的QImage并为QPainter启用剪切.

You can use the QImage method when you're zooming in realtime, too. It just depends on how fast you need it to be. You may need careful optimizations such as reusing the same QImage, and enabling clipping for your QPainter.

这篇关于在OpenGL中渲染矢量图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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