Legacy DirectX API Reference
Introduction to Legacy DirectX
This section provides an overview and detailed API reference for legacy versions of DirectX, including DirectX 9, DirectX 8, and earlier. While modern development typically utilizes DirectX 11, 12, or Vulkan, understanding these older APIs is crucial for maintaining existing applications and for historical context.
Legacy DirectX APIs were foundational to real-time graphics and multimedia on Windows. They offered a comprehensive suite of tools for developers to create immersive visual experiences.
Core DirectX APIs
The core of the DirectX API provides fundamental functionalities for graphics, input, audio, and networking.
Direct3DCreate9 LPDIRECT3D9 WINAPI Direct3DCreate9(UINT SDKVersion);
Creates a Direct3D 9 object. This object is used to enumerate devices, describe formats, and create Direct3D 9 interfaces.
Parameters
SDKVersion
: The DirectX SDK version.
Return Value
- On success, returns a pointer to the created Direct3D 9 object.
- On failure, returns
NULL
.
IDirect3DDevice9::CreateVertexBuffer HRESULT CreateVertexBuffer(UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle);
Creates a vertex buffer object. Vertex buffers store vertex data for rendering.
Parameters
Length
: The size of the vertex buffer in bytes.Usage
: Usage flags for the buffer (e.g.,D3DUSAGE_DYNAMIC
).FVF
: The flexible vertex format (FVF) code describing the vertex structure.Pool
: The memory pool for the buffer (e.g.,D3DPOOL_DEFAULT
).ppVertexBuffer
: A pointer to receive a pointer to the created vertex buffer.pSharedHandle
: A handle to a shared resource (rarely used).
Return Value
- On success, returns
S_OK
. - On failure, returns an error code.
Direct3D
Direct3D is the graphics subsystem of DirectX. It provides a hardware-accelerated interface for rendering 2D and 3D graphics.
Direct3D Overview
Direct3D abstracts the capabilities of graphics hardware, allowing developers to harness the power of the GPU for rendering. Key concepts include devices, swap chains, surfaces, and vertex/index buffers.
Key Direct3D Objects
IDirect3D9
: The main Direct3D object.IDirect3DDevice9
: Represents a graphics adapter.IDirect3DSwapChain9
: Manages the presentation of rendered frames.IDirect3DSurface9
: Represents a surface, such as a render target or depth buffer.IDirect3DVertexBuffer9
: Stores vertex data.IDirect3DIndexBuffer9
: Stores index data.
DirectInput
DirectInput provides a low-level interface for accessing input devices like keyboards, mice, joysticks, and gamepads. It allows for more precise control and efficient handling of input compared to standard Windows messages.
DirectInput Overview
DirectInput supports both immediate mode (polling devices periodically) and buffered mode (receiving device events as they occur). This flexibility is essential for responsive game controls.
DirectInput8Create HRESULT DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPVOID* ppvOut, LPUNKNOWN punkOuter);
Initializes DirectInput and creates an IDirectInput8 object.
Parameters
hinst
: Instance handle of the application.dwVersion
: The version of DirectInput to create (e.g.,DIRECTINPUT_VERSION
).riidltf
: The IID of the desired DirectInput interface (e.g.,IID_IDirectInput8W
).ppvOut
: Pointer to receive the created DirectInput object.punkOuter
: For COM aggregation.
Return Value
- On success, returns
S_OK
. - On failure, returns an error code.
DirectSound
DirectSound enables hardware-accelerated 3D positional audio. It provides capabilities for sound mixing, effects, and playback.
DirectSound Overview
DirectSound allows applications to control sound buffers, manage output formats, and apply effects like reverb. It was a key component for immersive audio in games.
Key DirectSound Objects
IDirectSound8
: The main DirectSound object.IDirectSoundBuffer8
: Represents a sound buffer for playback.IDirectSound3DListener8
: Manages the listener's position and orientation in a 3D soundscape.IDirectSound3DBuffer8
: Manages the position and properties of a sound source in 3D space.
DirectPlay
DirectPlay was a network API for online multiplayer games. It handled session management, message routing, and player synchronization.
DirectPlay facilitated network communication for games, abstracting lower-level protocols like TCP/IP and UDP. While superseded by newer networking solutions, it was instrumental in early online gaming.
DXGI (DirectX Graphics Infrastructure)
DXGI is a low-level API that handles enumerating adapters, managing swap chains, and other foundational graphics tasks. It serves as the common interface for modern DirectX APIs (Direct3D 10, 11, 12).
DXGI is essential for modern DirectX applications, providing the bridge between the application and the graphics hardware driver.
Key DXGI Objects
IDXGIFactory
,IDXGIFactory1
,IDXGIFactory2
: Manages DXGI objects, enumerates adapters.IDXGIAdapter
,IDXGIAdapter1
,IDXGIAdapter2
: Represents a graphics adapter.IDXGIOutput
,IDXGIOutput1
: Represents a display output.IDXGISwapChain
,IDXGISwapChain1
,IDXGISwapChain2
: Manages the presentation of rendered frames.
Other Legacy Features
Beyond the core components, DirectX also encompassed other features relevant to game development:
- DirectShow: Multimedia streaming and editing.
- DirectMusic: Advanced music playback and sequencing.
- DirectDraw: Legacy 2D graphics acceleration.
These components provided a comprehensive multimedia framework for Windows applications during their prime.