Absolute beginner question regarding APIs, frameworks, libraries...

Started by
3 comments, last by Paul C Skertich 11 years, 6 months ago
Hi, I've been learning C++ for some time now and I would like to make a basic game. But I have some questions about game programming in general - I really don't know the difference between (or the uses of) things like DirectX, OpenGL, etc.

From what I understand, DirectX and OpenGL are APIs... what exactly is an API, why/when would you use them for a game? What is something like XNA, then?

Further on, from what I understand, things like SDL and SFML are libraries - how are they separate from things like DirectX and OpenGL, are they used together/in conjunction? When would you use one over the other?

Finally, there's Unity, which from what I understand is an engine. So can you just use something like Unity to make a game and ignore the rest?

Thanks
Advertisement
In practice, the distinction is fuzzy, arbitrary and not really helpful.

In general, they're all "already written code you can use". You would use them when you don't want to spend the multiple man-years spent by experts in making the code you can use for free.
I'd agree with what Telastyn said: plenty of people will try to give your their One True Definition™, but in reality there aren't real "official" definitions that are universally agreed upon and it often isn't particularly useful to put effort into trying to classify things into one particular role.

An API, or Application Programming Interface, provides an interface to some (usually lower-level) functionality. In the case of OpenGL and Direct3d that functionality is talking to graphics hardware in order to draw things on the screen -- if you did not use an existing API you would have to write a different code implementation for each different piece of hardware you want your game to run on, but the API hides all that complexity from you and allows you to simply use the provided commands and data structures to describe what you want to happen, and then handles talking to the hardware for you.

A library (or "framework", just to throw another term at you!) is a piece of code -- generally a collection of related or semi-related functionality -- that has been pre-written for your usage. These terms are sometimes used interchangeably with "API" or "engine".

Most people consider the term "engine" to refer to a more complete software package -- potentially including tools and multiple libraries -- for completing some task, and it's usually designed for more specific rather than general usage. Looking at Unreal as an example, you have a fairly complete package that is designed for first or third person games: it includes all of the stuff you would need to create such a game -- physics, rendering, input handling, maps, etc. -- and all you need to do is create your game-specific functionality. Remember however that the terms "engine" and "library" or "framework" are sometimes used interchangeably, and just to be confusing might also be referred to as an API in some cases.


Don't get bogged down in the terminology though -- if you're not sure what something is, just check what capabilities and functionality is actually on offer and get on with the task at hand.


Hope that's somewhat helpful! smile.png

- Jason Astle-Adams

It's true that there's no need to get bogged down in terminology. But sometimes the best way to avoid that is to get answers to your questions.

Library
The term "Library" refers to a specific way functionality can be packaged for use by the application programmer.

Specifically, in a compiled language like C++, a set of functionality is compiled to object code (i.e., "link-able" .obj files), and made available in an "archive" or "library", which on windows is a .lib file (.lib files essentially contain a bunch of .obj files). The application programmer generally "includes" provided header files which declare functions and types implemented in the library, uses them in code, and links the library into the executable.

The term "library" says nothing about what type of functionality is provided, or what it might be used for.

API
As mentioned, API means "Application Programming Interface". "API" generally refers to a library, but is named for the interface (i.e., the contents of accompanying header files) to which the application code will be written, rather than the implementation in the library.

The phrase, "Application Programming" implies that the functionality provided is specific for creating some certain type of application. The Windows API is used for making Windows applications; The OpenGL ("Open Graphics Library") API is used for making graphical applications; Etc. APIs often deal with how the application interacts with the outside world - how it gets input and/or generates output.

In general, an API is a library but a library is not necessarily an API. The C++ standard library, for example, is mostly functionality for a program's internal processing. It's not designed for giving an application access to, or control over, any specific platform/environment.

Engine
A game engine is a unified set of run-time software technology designed to provide a good portion of the core functionality of a game. The thing that makes it an engine, is its frame-based multi-tasking nature. The thing that makes it a game engine is all the basic functionality it delivers that makes it useful for building games. (OpenGL and Direct 3D are not engines, for example. They provide nothing but a way to get graphics on screen.)

While not technically part of the engine itself, most engines would be useless without a set of accompanying tools for generating content specific to that engine, so a tool-set is sometimes thought of as part of the engine.

The term "engine" says nothing about how the functionality is delivered. It could, for example, be delivered as a set of libraries, or as source code for a sample game "stub". If it's a set of libraries, they could be considered an API for developing applications on that engine.

OpenGL
The "Open Graphics Library" is a cross-platform API for putting graphics on-screen.

Providers of all sorts of different platforms, that have graphics rendering ablilty, can implement the library for their platform. All implementations of the library work with the published OpenGL interface. That way, applications programmers can write applications using that interface, and they'll build and work on various different platforms, without alteration.

Direct X
Direct X is a Microsoft API for developing "multi-media" applications on Microsoft platforms. In addition to Direct 3D (their graphics API), it includes other components like Direct Sound and Direct Input.

SDL & SFML
SDL & SFML are video games APIs.

They provide facilities for such things as audio output, input acquisition, networking, threading, timing, etc. They work with, or along-side, OpenGL.

Unity
I don't really know much about Unity, but in general, any robust game engine will include all of the functionality provided by the graphics and video games APIs, and more (e.g., physics, collision, AI, game objects/entities, message passing, asset handling, load/save, GUI/menus, etc.).

As mentioned above I also agree but I can relate to the whole fuzziness. API's are a collection of libraries like as Windows API. What is a Windows API - it just that a collection of headers files, library files and whamo. DirectX is a API (Application Programming Interface) - a collection of libraries headers to create a DirectX Game. SDK is Software Development Kit - just as described is collection of libraries and header files to develop the software. Framework like .NET Framework is like a tree heirchy. System is a namespace that is used in CLI and C#. System::IO stems from System namespace - etc... You get the point! :)
Game Engine's WIP Videos - http://www.youtube.com/sicgames88
SIC Games @ GitHub - https://github.com/SICGames?tab=repositories
Simple D2D1 Font Wrapper for D3D11 - https://github.com/SICGames/D2DFontX

This topic is closed to new replies.

Advertisement