Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering Vector Graphics in OpenGL? [duplicate]

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.

like image 652
Jookia Avatar asked Nov 09 '10 02:11

Jookia


People also ask

Does OpenGL use vector graphics?

OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics.

Is OpenGL raster or vector?

However, OpenGL is a rasterizer. It's primary purpose is to convert a mathematical representation of a surface into a raster image. So in effect, the OpenGL scene is a vector “image” already.

Why do vector graphics not lose quality?

Because vector graphics are not composed of pixels they are resolution-independent. Vectors can be scaled to any size without losing quality.

How are vector graphics rendered?

Vector images and objects may be twisted, stretched and colored using mathematical operators in the software and rendered to the user through a graphical user interface (GUI). Transformations can also include set operations on closed shapes. Vector formats are ideal for drawings that are device independent.


1 Answers

I see most of the answers are about Qt somehow, even though the original question doesn't mention it. Here's my answer in terms of OpenGL alone (which also benefits greatly from the passage of time, as it could not have been given in 2010):

Since 2011, the state of the art is Mark Kilgard's baby, NV_path_rendering, which is currently only a vendor (Nvidia) extension as you might have guessed already from its name. There are a lot of materials on that:

  • https://developer.nvidia.com/nv-path-rendering Nvidia hub, but some material on the landing page is not the most up-to-date
  • http://developer.download.nvidia.com/devzone/devcenter/gamegraphics/files/opengl/gpupathrender.pdf Siggraph 2012 paper
  • http://on-demand.gputechconf.com/gtc/2014/presentations/S4810-accelerating-vector-graphics-mobile-web.pdf GTC 2014 presentation
  • http://www.opengl.org/registry/specs/NV/path_rendering.txt official extension doc

NV_path_rendering is now used by Google's Skia library behind the scenes, when available. (Nvidia contributed the code in late 2013 and 2014.)

You can of course load SVGs and such https://www.youtube.com/watch?v=bCrohG6PJQE. They also support the PostScript syntax for paths. You can also mix path rendering with other OpenGL (3D) stuff, as demoed at:

  • https://www.youtube.com/watch?v=FVYl4o1rgIs
  • https://www.youtube.com/watch?v=yZBXGLlmg2U

An upstart having even less (or downright no) vendor support or academic glitz is NanoVG, which is currently developed and maintained. (https://github.com/memononen/nanovg) Given the number of 2D libraries over OpenGL that have come and gone over time, you're taking a big bet using something not supported by a major vendor, in my humble opinion.

like image 164
Fizz Avatar answered Sep 22 '22 13:09

Fizz