Skip to main content
gamedev.net
🔒 Locked

How to write an API? Design tutorial?

Started by Samurai Jack Mar 28, 2006 at 12:15 AM 6 replies 1k views
Original Post
Samurai Jack
Samurai Jack
Greetings! I was wondering, are there any guidelines on how to create an API? I tried many times to write my own engine but there is allways something I do not like about the interface. For example I do not like Ogre3D or Irrlicht because they almost force you to derive from their baseclases to start an application. Some APIs you just plug in when required and you can use them like plain C. OpenGL for example. You just initialize it and call glBegin() .. glEnd() that's it. No derivations what-so-ever. Because of the object oriented nature of DirectX I do not like that some base variable IDirect3DDevice9 etc.. are lying arround in my global splace of a .lib or .dll. I would like to have them encapsulated. But on the other way, i would like to avoid this:

class CMyRenderDevice : public CMySingleton<CMyRenderDevice>
{
...
public:
bool BeginScene(void);
bool EndScene(void);
}

bool engineBeginScene(void)
{
CMyRenderDevice().GetSingleton().BeginScene();
}

bool engineEndScene(void)
{
CMyRenderDevice().GetSingleton().EndScene();
}
Any suggestions or even better tutorials how to achive souch things in the most elegant way? Thank you in advance!
Drew_Benton
Drew_Benton
Quick question first, are you trying to get a Graphics API Independet solution, or just something for D3D? If the latter, I have a method to share I was thinking about for a while and started to implement. I don't have time right now to explain, but if you are interested I'll make another post when I'm done with this project plan I have to do right now.
Samurai Jack
Samurai Jack
Indeed, I just need it for Direct3D. No platform independency no nothing. I just want it to be as simple and efficient as possible. I would just like to avoid to call simple methods that wrap arround classes and do the double work.
Samurai Jack
Samurai Jack
Hm, I like Winapi very much, because I do not need to include a lot of stuff to get it working. Just and some simple calls and I can start with a running window. No 10.000 includes, 20 libraries, no utilities no nothing. You just take it and use it - and it works.

Okay, It might have too many parameters, but it is very easy to bypass then with just NULL and that's it when not required.

But I do not like the concept of frame listeners like in Ogre or Irrlicht. I would just like to init, enter the loop and leave, with resource management etc...

In theory the basic idea of an engine is, that you just pass the parameters to the engine and everything else goes by itself - ogre is exactly that, but I would like an API more than OpenGL with functionality like DirectX.

I have written a lot of classes for DirectX but at the end, I almost never reuse them in projects, because I dislike this and that, I do not like the coding convetion, should I use namespaces or not, should it be a Lib or a DLL bla bla. Too much of balast.

I was hoping for a straigt forward idea, a plan I could stick to.
Samurai Jack
Samurai Jack
Thank you guys! Unreal public source and NOLF it is then.
Thank you very much for all help. Feel free to post!

Topic Locked

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

Sign in to reply to this topic.