OpenGL for DirectX

Started by
8 comments, last by svpace 21 years, 1 month ago
Hi, I have some experience with OpenGL but don''t know almost nothing about DirectX, but anyone know, or know to be impossible, or know that anyone is working on something like that, about implementing the OpenGL API on top of DirectX? Would be nice to use the same code and be able to compile OpenGL or DirectX graphics just with the switch of a library.
Advertisement
You mean a wrapper for DirectX with the same functions as OpenGL?

Join the World Wide Revolution:
Yes, something like that.
That''s how the DirectX support in Tribes2/Torque works, an OGL like wrapper over Direct3D.

Their D3D implementation isn''t the best, but it shows the task is very possible.
Yes, it can be done. You can create a wrapper for Direct3D that looks like OpenGL or you can create a custom API to suit your needs and then wrap the custom API around DirectX and OpenGL.

Some thing like this

            // Renderer.h - Base Rendererclass Renderer{  Renderer();  ~Renderer();  virtual void DoSomething(void)=0;}// D3DRenderer.h - Direct3D Rendererclass D3DRenderer : public Renderer{  D3DRenderer();  ~D3DRenderer();  void DoSomething(void);}// OGLRenderer.h - OpenGL Rendererclass OGLRenderer : public Renderer{  OGLRenderer();  ~OGLRenderer();  void DoSomething(void);}  //Then some where in your program have this      // Define what ever renderer you want to compile with#define OGL_RENDERER// or#define D3D_RENDERER#if defined(OGL_RENDERER)  #include "OGLRenderer.h"  OGLRenderer g_Renderer;#elif defined(D3D_RENDERER)  #include "D3DRenderer.h"  D3DRenderer g_Renderer;#else  #error No Renderer Defined#endif      


Ok I have tried to edit the bottom part like 5 times and the source tags still keep messing it up.


[edited by - Garrland on March 4, 2003 5:09:12 PM]
Garrland: the ideia is reuse OpenGL code in DirectX only platforms, so, building a new interface is not an option, but thanks for the reply anyway.

CheeseGrater: nothing like a library or something, so I can reuse instead of reinvent? maybe the Tribes guys published something? LGPL or free for non-comercial use would be good, but anything else would help.
Check out SciTech Software''s GLDirect. I never tried it, and don''t know what it is worth, but it seems like this is what you want. You can d/l a free trial.
If you''ve already written it in OpenGL, is there really any point in mapping that onto OpenGL? I mean, other than the Xbox, there isn''t really any machine that runs DirectX and not OpenGL.

This isn''t meant as a flame, I just wonder what your reasons for doing this are.
Bleh, I meant " is there really any point in mapping that onto DirectX?"

I can type faster than I can think. And the sad thing is, I can''t even type that fast.
quote:Original post by svpace
CheeseGrater: nothing like a library or something, so I can reuse instead of reinvent? maybe the Tribes guys published something? LGPL or free for non-comercial use would be good, but anything else would help.


Don''t know of anything LGPL or free, but if you head to www.garagegames.com and plunk down $100 for the engine, you''ll also get the source to their D3D wrapper.

AP: Switching API''s makes the most sense when you''ve got buggy or incomplete drivers for one but not the other. This is less common now that it used to be, but some older or off-brand video cards still do a lot better with D3D than with openGL.

This topic is closed to new replies.

Advertisement