Direct3D (DirectX 9.0) Code Samples - Page 1


Demonstrates how to initialize Direct3D. This sample is by far the simplest of all Direct3D samples on this page. If you know nothing about Direct3D, you probably need to start here. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant C++ Keywords: Direct3DCreate9, GetAdapterDisplayMode, CheckDeviceFormat, GetDeviceCaps, CreateDevice, Clear, BeginScene, EndScene, Present, Release, D3D_SDK_VERSION, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16, D3DCREATE_HARDWARE_VERTEXPROCESSING, D3DSWAPEFFECT_DISCARD, D3DCLEAR_TARGET, D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE, BackBufferFormat, SwapEffect, Windowed, EnableAutoDepthStencil, and AutoDepthStencilFormat.

Relevant C# Keywords: System.Windows.Forms.Form, System.Drawing.Size, SetStyle, ControlStyles.AllPaintingInWmPaint, ControlStyles.Opaque, Invalidate, Show, Manager.CheckDeviceFormat, Manager.Adapters.Default.Adapter, DeviceType.Hardware, Manager.Adapters.Default.CurrentDisplayMode.Format, Usage.DepthStencil, ResourceType.Surface, DepthFormat.D16, Caps, Manager.GetDeviceCaps, DeviceCaps.SupportsHardwareTransformAndLight, CreateFlags.HardwareVertexProcessing, CreateFlags.SoftwareVertexProcessing, PresentParameters, d3dpp.BackBufferFormat, Format.Unknown,SwapEffect, SwapEffect.DiscardWindowed, EnableAutoDepthStencil, AutoDepthStencilFormat, DepthFormat.D16, PresentationInterval, PresentInterval.Immediate, Clear, BeginScene, EndScene, and Present.

  • Download (Last Updated: 05/27/05 - C++)
  • Download (Last Updated: 06/15/05 - C#)


Full-Screen Initialization

This sample demonstrates how to probe the hardware for specific Display or Adaptor Modes and hardware support suitable for a full-screen application with Direct3D. Check out the OpenGL source code page for the OpenGL equivalent of this sample.

Relevant C++ Keywords: GetAdapterModeCount, EnumAdapterModes, CheckDeviceType, CheckDeviceFormat, GetDeviceCaps, D3DFMT_X8R8G8B8, D3DDISPLAYMODE, Width, Height, Format, RefreshRate, and D3DUSAGE_DEPTHSTENCIL.

Relevant C# Keywords: AdapterInformation, Manager.Adapters, Format.X8R8G8B8, RefreshRate, Width, Height, Manager.CheckDeviceType, Manager.Adapters.Default.Adapter, DeviceType.Hardware, Manager.CheckDeviceFormat, Manager.Adapters.Default.CurrentDisplayMode.Format, Usage.DepthStencil, ResourceType.Surface, DepthFormat.D16, and Windowed.

  • Download (Last Updated: 05/27/05 - C++)
  • Download (Last Updated: 06/15/05 - C#)


View Ports

This sample demonstrates how to set multiple view ports using DirectX 9.0.

Relevant C++ Keywords: SetViewport, Clear, BeginScene, EndScene, Present, Y, X, Width, Height, MinZ, MaxZ, and D3DVIEWPORT9.

Relevant C# Keywords: Mesh, Material, Microsoft.DirectX.Direct3D.Viewport, Viewport, X, Y, Width, Height, MinZ, MaxZ, this.ClientSize.Width, Transform.View, Matrix.Identity, Geometry.DegreeToRadian, Matrix.Translation, Matrix.RotationYawPitchRoll, Transform.View, AND Transform.World.

  • Download (Last Updated: 06/02/05 - C++)
  • Download (Last Updated: 06/15/05 - C#)


Multiple Devices

This sample demonstrates how to render to multiple windows using multiple devices under DirectX 9.0. You should note that this is not considered the most optimal way to manage two windows from one application. The preferred method is to create one Direct3D device and use CreateAdditionalSwapChain() to create additional front and back buffer pairs for rendering in multiple windows. This allows two windows to share resources like meshes and textures and keeps the driver from performing a costly context switch between multiple devices. The usage of CreateAdditionalSwapChain() is covered in the sample below.

Relevant Keywords: CreateDevice, Present, BeginScene, EndScene, and D3DPRESENT_PARAMETERS.


Swap Chains

This sample demonstrates how to render to multiple windows using swap chains under DirectX 9.0. This is far more efficient than creating multiple Direct3D devices, which is covered in the above sample.

Relevant Keywords: GetSwapChain, CreateAdditionalSwapChain, CreateDevice, GetBackBuffer, SetRenderTarget, Present, BeginScene, EndScene, D3DPRESENT_PARAMETERS, and LPDIRECT3DSWAPCHAIN9.