开发者

OpenGL Save VBO To File(Obj or something else)

Has anyone managed to export a OpenGL VBO into an external file format at runtime? I'd be grateful for any pointers in the right direction, since I h开发者_如何学Pythonave no idea of how I would go about this.


OpenGL is just a sophisticated drawing API. The data in a Buffer Object is arbitrary. It is your program, that gives meaning to it (and to OpenGL, BTW). Someone had to upload that data into a VBO (glBufferData calls) and make sense of it by issuing the right calls to glDrawElements or glDrawArrays. So whereever the data came from in the first place, you'd better write a file from there, avoiding the detour over OpenGL. However if you have no copy araound in your program, then you can use glGetBufferSubData to obtain a copy of the data in the buffer.

A reason that you have no copy of the data in your program could be, that you memory mapped the buffer into your program using glMapBuffer. You can also use such a mapping (preferrable with read only access) to retrieve the data in the buffer.

Together with some logic you must supply to make sense of it you can write any file format you like. But the burden of writing the file is on you.


If you just want to export vertices and triangular data, have a look at the following formats:

  • VRML
  • PLY
  • STL

These are ascii formats, easy to understand, and straightforward to write.

Obviously, as mentioned in comments you must have knowledge of how data is coded in the VBO, since it is just an array of bytes. The idea would then be to get the content of the VBO, decode it into vertices and triangles using specific application logic, and export this data in one of the file formats.


http://assimp.sourceforge.net/ is one way to do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜