OpenGL 中 .x 文件的模型,DirectX 和 OpenGL 之间的区别
我对在 DirectX 中使用导出到 .x 文件的 3D 模型缺乏经验。 例如,用于使水面或某些物体成为星星、汽车、草地或其他物体。 我可以像在 DirectX 中那样在 OpenGL 中以类似的方式执行此操作吗?我的意思是使用 .x 文件来渲染 3D 模型?或者其他文件,还是这样不好?如果这是不好的方式,我该怎么办?
情况:简单的 3D 游戏项目 OpenGL + C#,我已经从高度图渲染了地形,我需要通过对象、草、水、传送来改进它。所以我正在寻找渲染 3D 对象的简单方法。
I have little experience with using 3D models exported to .x files in DirectX.
For example for make watersurface or some objects star, car, grass or whatever.
Can I do it in OpenGl similar way like in DirectX? I mean using .x file to render the 3D model? Or other file, or is that bad way? If it is bad way, what should I do?
Situation: project of simple 3D game OpenGL + C#, I have rendered terrain from Height map and I need to improve it by objects, grass, water, teleports.. so I'm finding easy way to render 3D objects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,也不是。让我解释一下。
DirectX .x 文件格式随着 DirectX 3 的诞生而诞生,这简直是一团糟。即使加载最简单的几何图形也是一项非常累人的任务。因此,Direct3D 环境中添加了对从文件加载模型几何图形的支持。
然而,DirectX 从未强制执行特定的文件格式,随着它的成熟,Direct3D 版本 7 左右的某个地方变得可用。一旦将几何图形导入 Direct3D 变得简单,就不再需要 .x 文件格式。坦率地说,只有很少的严肃程序真正使用 .x 作为其资产。
OpenGL 从来不需要内置格式,因为设置和绘制几何图形(当然已经读入内存)可以用短短 10 行 C 代码来管理。所以唯一的困难在于将文件格式解析为内存中的结构。这不是为绘图而设计的 API 的任务,而是为执行 I/O 的库而设计的任务。
长话短说:OpenGL 没有内置对某些文件格式的支持,但您可以使用任何您喜欢的文件格式,并将其导入 OpenGL。 .x 文件格式有详细记录,您可以找到现成的库来加载或编写自己的库。
Yes, and no. Let me explain.
The DirectX .x file format came to life with DirectX 3, which was an utter mess. Loading even the most simple geometry was an awfully exhausting task. As of such, support for a loading model geometry from files was added into the Direct3D environment.
However DirectX never enforced a specific file format, and as it matured, somewhere around version 7 Direct3D became usable. As soon as getting geometry into Direct3D became something simple, the .x file format was no longer needed. And frankly, there are only very little serious programs that actully use .x for their assets.
OpenGL never had the need for a builtin format, because setting up and drawing geometry – that has already been read into memory of course – could be managed in as little as 10 lines of C code. So the only difficulty lies in parsing a file format into structures in memory. This is not a task for a API designed for drawing stuff, bur for libraries that are designed to do I/O.
To make a long story short: OpenGL has no built in support for some file format, but you can use any file format you like to, and coax it into OpenGL. The .x file format is well documented and you can find ready to use libraries to load or write your own.
简短的回答是否定的。在 OpenGL 中你无法做到这一点。首先,让我澄清一下这里发生了什么。
DirectX 与 OpenGL 一样,是一种高性能图形 API。虽然个别功能存在差异,但您可以认为它们几乎相同。
然而,DirectX 与 OpenGL 有很大不同。具体来说,Microsoft 有许多基于 DirectX 构建的工具和库。例如,XNA 库、Visual Studio 加载项等。
当您拥有“.x”文件时,您真正要做的是使用构建在 DirectX 之上的部分附加库和机制来加载和显示模型。
虽然有许多库可用于加载模型并在 OpenGL 中显示它们,但它们并不像 DirectX 那样“现成”。
对于您的游戏,如果您要使用 OpenGL,我建议您坚持为 3D 资源使用不同的文件格式。 COLLADA 将是一个很好的起点。
The short answer is no. You cannot do that in OpenGL. First, let me clarify what is going on here.
DirectX, like OpenGL, is a high-power graphics API. While there are differences in individual features you can think of them as nearly identical.
However, DirectX differs from OpenGL in a big way. Specifically, Microsoft has lots of tooling and libraries built on top of DirectX. For example, the XNA library, Visual Studio add-ins, and so on.
When you have a ".x" file, what you are really doing is using part of the additional libraries and machinery built on top of DirectX to do the loading and displaying of the model.
While there are lots of libraries for loading models and displaying them in OpenGL, they aren't "in the box" like they are with DirectX.
For your game, if you are going with OpenGL I would recommend you stick with a different file format for your 3D assets. COLLADA would be a good starting point.