OpenGL 将 VBO 保存到文件(Obj 或其他文件)
有人设法在运行时将 OpenGL VBO 导出为外部文件格式吗?我将不胜感激任何正确方向的指示,因为我不知道我将如何去做。
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 have no idea of how I would go about this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
OpenGL 只是一个复杂的绘图 API。缓冲区对象中的数据是任意的。是你的程序赋予了它(以及 OpenGL,顺便说一句)意义。有人必须将该数据上传到 VBO(
glBufferData
调用),并通过对glDrawElements
或glDrawArrays
发出正确的调用来理解它。因此,无论数据最初来自哪里,您最好从那里编写一个文件,避免绕过 OpenGL。但是,如果您的程序中没有副本,则可以使用glGetBufferSubData 来获取缓冲区中数据的副本。您的程序中没有数据副本的原因可能是您使用
glMapBuffer
将缓冲区内存映射到您的程序中。您还可以使用此类映射(最好具有只读访问权限)来检索缓冲区中的数据。结合您必须提供的一些逻辑来理解它,您可以编写您喜欢的任何文件格式。但写入文件的负担由您承担。
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 toglDrawElements
orglDrawArrays
. 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 useglGetBufferSubData
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.
如果您只想导出顶点和三角形数据,请查看以下格式:
这些是 ascii 格式,易于理解且易于编写。
显然,正如评论中提到的,您必须了解数据在 VBO 中的编码方式,因为它只是一个字节数组。然后,我们的想法是获取 VBO 的内容,使用特定的应用程序逻辑将其解码为顶点和三角形,并以其中一种文件格式导出该数据。
If you just want to export vertices and triangular data, have a look at the following formats:
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/ 是实现此目的的一种方法。
http://assimp.sourceforge.net/ is one way to do this.