   How do you code for both DX and opengl ?
  Is there a way of porting your code written uinsg one API to the other API ?    ''A library consists of the actual binary code behind the API. You link your game code to the library to make everything work.'' 
  yes.but, depending on how it was programmed, it may or may not be easy there is a series of articles in the "articles and resources" section called "striving for graphics API independence" (or something close to that at least) which may help you out. 