Question

This is a pretty beginner question, but given that I render a complex shape in OpenGL which requires a lot of calculations, is there anyway to export that to a state like a model that can be opened again later given you wont edit it again?

I can't create them outside the program (with something like Blender) since the shape is computed when the program starts. The render then gets translated, rotated, drawn over, etc. Note, that I don't need to edit the shape though, but I do want it in a 3D state so saving an image isn't an option.

I'm using OpenTK 1.0, VB.NET (.NET 4)

Was it helpful?

Solution

The obvious possibility would be to write your vertices to a file, and then re-load them when needed. Unless you have specific reasons to do otherwise, it's probably best to use one of the many existing file formats for this, such as Wavefront OBJ, Ogre3d mesh XML files, etc.

OTHER TIPS

THis sounds like an ideal situation for OpenGL display lists. The way you use them is to first ask OpenGL for a display list id to use:

GLuint draw_id = glGenLists(1);

(You can ask for several consecutive ids at a time, but in this case we are only asking for 1) Then, first time through your draw routine, call glNewList:

glNewList(draw_id, GL_COMPILE);
<do compute intensive drawing here>
glEndList();

Note that this will not actually render your shape (you can use GL_COMPILE_AND_EXECUTE in glNewList, which will render your shape, but that is generally discouraged)

Now, whenever you need to draw your object:

< set up your OpenGL matrices >
glCallList(draw_id);

And finally, when you are done with it, you can use glDeleteLists.

Display lists can actually speed up rendering, as some optimizations can be done, and all function call overhead is removed.

Now, technically, OpenGL display lists have been deprecated (not removed, however!) in OpenGL 3.0 and above (along with glTranslate, glVertex glBegin... grrr), but they should still work for the foreseeable future. To be future proof, you should use vertex arrays, but that is a fair bit more complicated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top