It's smaller, faster, and many people say easier to learn than DirectX. I've just started learning it off of
http://nehe.gamedev.net 's tutorials, and it isnt hard at all so far.
I beg to differ on the faster part. I'm not sure that any one API is faster than the other. Actually it is quite an arrogant assumption because the HAL is written by the video card manufacturer not Microsoft. So if it is slower than OpenGL it is because the manufacturer of the driver and/or HAL goofed and has nothing to do with COM or the DirectX framework. Microsoft lays down the standard and the video card manufacturer writes the actual card-specfic code to interface with the hardware.
So to say OpenGL is faster is to assume that DirectX is doing most of the work when in fact it is not, the HAL is. Direct3D and DirectX in general will be the only API in the future simply because it supports so much more than just a graphics API. DirectX is a complete video game programming platform that supports just about everything made for a PC or ever going to be made. As long as Microsoft has the OS market, DirectX will be the prime choice for game companies to develop with. And since DirectX is also supported on the XBox (or a derivative thereof...close enough though) then DirectX is simply here to stay. Do yourself a favor and learn it well. IMO OpenGL is extremely limited simply because it only supports graphics and only operates correctly on cards that natively support it. I think that 3rd party graphic APIs are on the way out....as well as 3rd party sound APIs like Creative's EAX unified. Eventually it will all come down to the card level or hardware level and DirectX will be the way to interface with it.
My advice is to learn DirectX. Do not listen to the people who say it is hard or impossible to learn. COM is a fundamentally brilliant concept and it is NOT that difficult to understand. If you understand pointers and objects then you can use it. You only need a very limited amount of knowledge of COM to use DirectX - very limited. No aggregated COM here - just the basics. DirectX is a huge toolbox sitting out there. Open one drawer of the toolbox and it might expose several other drawers of tools or simply several other tools. That's it. Simple and brilliant.
Go over to www.gamedev.net and look at their books and resources section. Purchase to your heart's content and you won't regret it.
You decide for yourself whether you want to learn OpenGL or DirectX. With DX once you learn graphics....sound, networking, input, etc., all follow the same basic setup and shutdown steps. Very simple.
Here is a sample of one way to get DirectInput up and running. The second example is for the mouse. After you write this code...you simply check for state changes and thats it. Total mouse support for every single mouse that can be connected to an x86 machine running any version of Windows 98/XP/2000.
CDInput.h
Code:
#ifndef CDINPUT
#define CDINPUT
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
class CDInput
{
protected:
IDirectInput8 *_pDI8;
public:
CDInput() {};
~CDInput() {_pDI8->Release();};
HRESULT Init(HINSTANCE hinst);
};
#endif
CMouse.h
Code:
#include "CDInput.h"
#define LMB 0
#define RMB 1
#define MMB 2
class CMouse:virtual public CDInput
{
protected:
IDirectInputDevice8 *_pDID8;
public:
CMouse() {};
~CMouse() {if (_pDID8) _pDID8->Unacquire();
if (_pDID8) _pDID8->Release();};
HRESULT Create(HWND window);
//Share our data with the world
DIMOUSESTATE _mousestate;
HRESULT Update(void);
};
CMouse.cpp
Code:
#include "CMouse.h"
HRESULT CMouse::Create(HWND window)
{
if (FAILED(_pDI8->CreateDevice(GUID_SysMouse,&_pDID8,NULL)))
{
::MessageBox(0,"Failed to create mouse device",0,0);
}
if (FAILED(_pDID8->SetCooperativeLevel(window,
DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
{
::MessageBox(0,"Failed to set mouse cooperative level",0,0);
}
if (FAILED(_pDID8->SetDataFormat(&c_dfDIMouse)))
{
::MessageBox(0,"Failed to set mouse data format",0,0);
}
if (FAILED(_pDID8->Acquire()))
{
::MessageBox(0,"Failed to acquire mouse",0,0);
}
//::ShowCursor(false);
return true;
}
HRESULT CMouse::Update(void)
{
if (FAILED(_pDID8->GetDeviceState(sizeof(DIMOUSESTATE),(LPVOID)&_mousestate)))
{
return FALSE;
} else return true;
}
Done. Total mouse support.