How to use API's

Started by
5 comments, last by SumDude 20 years, 1 month ago
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?
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                          
Looking for video game music? Check out some of my samples at http://www.youtube.c...ser/cminortunes            
                                                          
I'm currently looking to create music for a project, if you are interested e-mail me at cminortunes@gmail.com    
                                                          
Please only message me for hobby projects, I am not looking to create music for anything serious.
Advertisement
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
"There is no dark side of the moon." - Pink Floyd
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.
-Unsuspected
compatibility and SPEED
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
I hate when idiots just pull stuff out of their ass.
Don''t listen to Agony. It is not possible to make your own API.

At best, you can just make a wrapper for an API or two.
-Unsuspected
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,

e.g.
void DLL_PaintImage(void* dest,long dx,long dy,long dw,long dh,void* source,long sx,long sy,long rasterop)
{
BitBlt(dest->hdc,dx,dy,dw,dh,source->hdc,sx,sy,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,

www.EDIGames.com

www.EtherealDarkness.com



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

Raymond Jacobs, Owner - Ethereal Darkness Interactive
www.EDIGames.com - EDIGamesCompany - @EDIGames

This topic is closed to new replies.

Advertisement