user1097772
user1097772

Reputation: 3529

Models from .x files in OpenGL, difference between DirectX and OpenGL

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.

Upvotes: 1

Views: 1298

Answers (2)

datenwolf
datenwolf

Reputation: 162164

Can I do it in OpenGl similar way like in DirectX?

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.

Upvotes: 1

Chris Smith
Chris Smith

Reputation: 18712

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.

Upvotes: 1

Related Questions