Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

svpace

OpenGL OpenGL for DirectX

This topic is 5679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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 Renderer

class Renderer
{
Renderer();
~Renderer();
virtual void DoSomething(void)=0;
}

// D3DRenderer.h - Direct3D Renderer

class D3DRenderer : public Renderer
{
D3DRenderer();
~D3DRenderer();
void DoSomething(void);
}

// OGLRenderer.h - OpenGL Renderer

class 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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!