Skip to main content
gamedev.net
🔒 Locked

API independant engine

Started by kulik 3 replies 400+ views
Original Post
kulik
kulik
I want to write API independant engine. I want to use OpenGL and Direct3D for graphics. I understand both, but how to put it together? Polymorphic classes for OpenGL and DirectX drawing or drivers? How games like HalfLife took care about that?
fyhuang
fyhuang
Try using a central interface:



class CGraphics
{
virtual void SetMode( int w, int h );
};



And deriving a seperate class for each API:



class CDirectX : CGraphics
{
LPDIRECT3DDEVICE8 Device;
void SetMode( int w, int h );
};

class COpenGL : CGraphics
{
GLRC hRC;
void SetMode( int w, int h );
};



And then all you would have to do is to keep a pointer to a CGraphics interface and dynamically allocate whichever class you need.

[edit]Forgot to declare as virtual...

[edited by - fyhuang on May 16, 2004 9:13:37 AM]
- fyhuang [ site ]
SuperBoy
SuperBoy
Take a look at OGRE as an example. http://www.ogre3d.org

That abstracts from the APIs.
sagwagon
sagwagon
Look at the irrlicht engine source, it does d3d, ogl, and software.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.