Direct3D 9 API Reference

This section provides detailed reference information for the Direct3D 9 Application Programming Interface (API).

Overview

Direct3D 9 is a powerful graphics API that allows developers to create high-performance 2D and 3D graphics for Windows. It offers extensive control over the rendering pipeline, from vertex processing to pixel shading.

Key Interfaces

Explore the core interfaces that form the foundation of Direct3D 9:

IDirect3D9 Interface

The IDirect3D9 interface is the entry point for Direct3D 9. You use it to query device capabilities, enumerate available hardware adapters, and create Direct3D devices.

Methods

Method Description
CreateDevice Creates a Direct3D device for rendering.
GetAdapterCount Retrieves the number of display adapters present on the system.
GetAdapterIdentifier9 Retrieves the identifier of a display adapter.
GetDeviceState Retrieves the current state of a Direct3D device.

CreateDevice

Creates a Direct3D device for rendering.

HRESULT CreateDevice(
  UINT Adapter,
  D3DDEVTYPE DeviceType,
  HWND hFocusWindow,
  DWORD BehaviorFlags,
  D3DPRESENT_PARAMETERS *pPresentationParameters,
  IDirect3DDevice9 **ppReturnedDevice
);

IDirect3DDevice9 Interface

The IDirect3DDevice9 interface represents a graphics adapter and is used to perform all rendering operations.

Methods

Method Description
BeginScene Marks the beginning of a scene.
EndScene Marks the end of a scene.
Clear Clears the render target or depth-stencil buffer.
Present Presents the next frame to the user.
SetVertexDeclaration Sets the current vertex declaration.
DrawPrimitive Renders primitives.

BeginScene

Marks the beginning of a scene. All drawing commands should be issued between BeginScene and EndScene.

HRESULT BeginScene( void );

EndScene

Marks the end of a scene.

HRESULT EndScene( void );

Clear

Clears the render target or depth-stencil buffer.

HRESULT Clear(
  DWORD Count,
  const D3DRECT *pRects,
  DWORD Flags,
  D3DCOLOR Color,
  float Z,
  DWORD Stencil
);

Present

Presents the next frame to the user.

HRESULT Present(
  const RECT *pSourceRect,
  const RECT *pDestRect,
  HWND hDestWindowOverride,
  const RGNDATA *pDirtyRegion
);

SetVertexDeclaration

Sets the current vertex declaration, which defines the vertex data format.

HRESULT SetVertexDeclaration(
  IDirect3DVertexDeclaration9 *pDecl
);

DrawPrimitive

Renders a sequence of primitives using the current vertex data and vertex buffer.

HRESULT DrawPrimitive(
  D3DPRIMITIVETYPE PrimitiveType,
  UINT StartVertex,
  UINT PrimitiveCount
);

Structures

D3DPRESENT_PARAMETERS

Structure containing parameters for device creation and presentation.

typedef struct D3DPRESENT_PARAMETERS_ {
  UINT                BackBufferWidth;
  UINT                BackBufferHeight;
  D3DFORMAT           BackBufferFormat;
  UINT                BackBufferCount;
  D3DMULTISAMPLE_TYPE MultisampleType;
  DWORD               MultisampleQuality;
  D3DSWAPEFFECT       SwapEffect;
  HWND                hDeviceWindow;
  BOOL                Windowed;
  BOOL                EnableAutoDepthStencil;
  D3DFORMAT           AutoDepthStencilFormat;
  DWORD               Flags;
  UINT                FullScreen_RefreshRateInHz;
  UINT                PresentationInterval;
} D3DPRESENT_PARAMETERS, *LPD3DPRESENT_PARAMETERS;

D3DVIEWPORT9

Structure defining the viewport.

typedef struct D3DVIEWPORT9_ {
  DWORD X;
  DWORD Y;
  DWORD Width;
  DWORD Height;
  float MinZ;
  float MaxZ;
} D3DVIEWPORT9, *LPD3DVIEWPORT9;