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

How to use API's

This topic is 5002 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

This may seem like a stupid question but just answer it please. I know how to use API''s to make simple programs but i want to make a Graphics Engine so i don''t have to work with the API directly. Is it a good idea to use coding from a book or site as a reference in an engine or put it in your coding and edit them to what is needed?

Share this post

Link to post
Share on other sites
If you are making your OWN game engine, you would do well to make your own code using books for reference rather than taking the code as a whole and plonking it into your own project. For one, it is imperative that you know how your game engine works the best and that is possible only if you write your own code. Secondly, the requirements of your project may well be different from that of the book. Remember, most books are written with the lowest common denominator in mind. Your game engine may require a totally different direction.

"There is no dark side of the moon." - Pink Floyd

Share this post

Link to post
Share on other sites
You can''t really make a graphical game w/o DX or OpenGL. Video cards are made to comply with these APIs, so you must use them if you want compatibility across almost all video cards.

Share this post

Link to post
Share on other sites
Even if you don''t use another API, you''ll still end up using your API. So regardless, you''re going to be using some API or another. The hope, I''m sure, is that your API will be easier and more intuitive for you to use, than if you were to work with DirectX or OpenGL or some other API.

I''d suggest that you come up with a design of how you want your API to function. What would be the typical way that you want to initialize things, alter things, render things, etc.? Most likely, you''re working for an abstraction, which means that your API should be simpler, which will make it easier to use, but will also limit flexibility. So it''s up to you to decide how much flexibility you need versus simplicity, and plan from there. Once you have a pretty thorough idea of how you want your API to work, make sure that you can implement it in terms of the other API. If not, you''ll have to do a bit (or a lot) of redesign. But once you get it implemented, you''ll now be able to just work with your own API, which should hopefully feel much more natural to use, at least for you.

Share this post

Link to post
Share on other sites
Ok, Ok=)

I will set things straight=)

what your looking for is called API Abstraction.

that is, creating a translation layer between your API and a 'real' API.

the benefit of this is you can change the 'glue' that binds the two API interfaces so that your API can use multiple API's on the other end. Asuming your using windows, the easiest way to do this is using a Dynamicly(runtime) Loaded DLL module.

lets take the BitBlt function for example.

in your API you have a function called 'PaintImage'
which takes the parameters,

(void* dest,long dx,long dy,long dw,long dh,void* source,long sx,long sy,long rasterop)

these parameters logicaly provide what is needed for a bit block transfer,

when the dll is loaded you point the PaintImage function to the DLL function called PaintImage,

the dll then translates it into a real api call to, say, GDI or DirectDraw,

void DLL_PaintImage(void* dest,long dx,long dy,long dw,long dh,void* source,long sx,long sy,long rasterop)

in order to make your engine use a new API, simply write a new DLL to provide the function translation.

I wrote an entire framework that abstracts Graphics,Audio and Networking, using DLL's

it works very well=D

please contact me via AIM,'EtherealDarknes' if you want clarrification on any points.

Good Luck,

Raymond Jacobs,

[edited by - EDI on April 6, 2004 3:46:25 PM]

Share this post

Link to post
Share on other sites