views:

216

answers:

2

Are there any tools and/or documentation providing a mapping from DirectX to OpenGL? If you had to do a conversion, how would you approach it and what would you use?

I know that ATI Technologies provides HLSL2GLSL, but my understanding is that this is just for shader languages and not a full coverage of the APIs.

+3  A: 

The concepts are very similar, but the APIs are very different between DirectX and OpenGL. Automatic conversion is not going to be very straightforward...

Personally, if I had a project and was trying to convert from one solution to the other, I would actually try to convert to a rendering library that supports both, such as Ogre, Irrlicht, or a commercial engine. This way, you can support both DX and OpenGL in one code base.

Reed Copsey
+1 for mentioning irrlicht
George Edison
The source app actually uses Allegro, which uses DirectX on Windows and I'm-not-sure-what-but-apparently-not-OpenGL on other platforms. I grepped the Allegro sources for "opengl" and got no hits, which is why I'm saying that.Allegro may be using OpenGL in the next release for non-Windows, but I don't think it does at present. If it did, I'd be set.
Buggieboy
If you're using Allegro, you can add AllegroGL for OpenGL support: http://wiki.allegro.cc/index.php?title=AllegroGL If you move to the latest version (4.9+), it supports OpenGL out of the box.
Reed Copsey
+1  A: 

A long time ago there were proprietary OpenGL-to-DirectX wrappers, used in games, which were as simple as single DLL exposing (sub)set of OpenGL commands can be.

On the other hand, faking DirectX (Direct3D) with OpenGL could be much harder, because you have to support the whole COM thing. So I guess you would have to replicate the required interfaces and only then write the actual wrapper.

Tomasz Zielinski
I'm also wondering about WINE. Does it need to convert DirectX calls to OpenGL to run on a Mac? If so, I'm thinking that I might learn something by examing how it does that.
Buggieboy
I think that yes, WINE converts DirectX to OpenGL, otherwise I cannot imagine how could games could work under it.
Tomasz Zielinski