Is there any kind of application, tool, lib, ... that generates OpenGL functions from a vector image? To avoid any misunderstanding: I don't want to render something like an SVG file in my 2D OpenGL project, I want to create vector image in my favourite vector app and convert it to OpenGL code instead of create it by code. That will saves lots of time.
Asked
Active
Viewed 2,686 times
2
-
If not SVG then what? An Adobe Illustrator .ai file? – jowo Jan 12 '12 at 03:55
-
the point was i "don't" want to "render" the "file", no matter what it is – mk.persia Jan 12 '12 at 04:08
-
I meant what file format do you want to convert from. You are going to need a format to save to from your vector app. And then a converter that will make it into a file easily loaded into an OpenGL vertex buffer. – jowo Jan 12 '12 at 07:42
-
I would like a software that write code for me too. – Luca Jan 12 '12 at 09:52
1 Answers
5
Don't generate OpenGL code. Store the vertex data in a form that's ready to load into a VBO. It's OK to generate code for the data — something like this:
struct { float position[3]; float texcoord[2]; float color[4]; } vertices[] =
{
// Auto-gen code here...
{ {1, 1, 0}, {0, 1}, {1, 0, 1, 1} },
...
};
But you might find that it's just as easy (and faster to compile) if you memory map the data straight in from a binary data file. Of course, the code version has the advantage of living right inside your executable without having to mess around with app resources, which in turn has the disadvantage of not letting you change the vector image without a recompile.

Marcelo Cantos
- 181,030
- 38
- 327
- 365
-
tanx 4 ur rply, the problem is the shapes are more complicated than that, and they are going to be animated. your solution is a smart one and works for some static projects. Unfortunately not mine :( – mk.persia Jan 12 '12 at 04:16
-
@mk.persia: Without knowing the specifics, it's difficult to say whether they suit your problem or not, but I will make some points that you should consider: 1) VBOs don't limit what you can draw relative to immediate mode; they mainly provide a different way to store the vertex data (though you may need other data structures to identify which segments of the array represent distinct shapes, etc.). 2) VBOs support dynamically-changing data. – Marcelo Cantos Jan 12 '12 at 04:31
-
-
I don't have any to hand, but you can google around for GL_DYNAMIC_DRAW and GL_STREAM_DRAW. The basic idea is to set the initial buffer contents with `glBufferData()` and one of the aforementioned *usage* enums, then update it as often as necessary with `glBufferSubData()`. – Marcelo Cantos Jan 12 '12 at 09:04
-
One more point just occurred to me. If you memory map the data with copy-on-write semantics (`MAP_PRIVATE` if using `mmap()`), you can modify the buffer in-place. – Marcelo Cantos Jan 12 '12 at 09:42