Direct3D - Creating a Device

Adapted from this blog entry.



This example creates a Direct3D device: import clr clr.AddReference("System.Drawing") clr.AddReference("System.Windows.Forms") clr.AddReference("Microsoft.DirectX.Direct3D")

from System.Drawing import * from System.Windows.Forms import * from Microsoft.DirectX.Direct3D import *

class CreateDevice(Form): def __init__(self): self.ClientSize = Size(400, 300) self.Text = "D3D Tutorial 01: CreateDevice" self.device = None self.Paint += lambda *_: self.render self.initializeGraphics

def initializeGraphics(self): presentParams = PresentParameters presentParams.Windowed = True presentParams.SwapEffect = SwapEffect.Discard

self.device = Device(0, DeviceType.Hardware, self,                             CreateFlags.SoftwareVertexProcessing,                              presentParams)

def render(self): if not self.device: return

self.device.Clear(ClearFlags.Target, Color.Blue, 1.0, 0)

self.device.BeginScene

# Here is where you put # Your code

self.device.EndScene self.device.Present

frm = CreateDevice Application.Run(frm)

You can use the interactive interpreter to get help on Direct3D objects: >>> print help(VertexBuffer) Help on VertexBuffer in module Microsoft.DirectX.Direct3D in Microsoft.DirectX.D irect3D, Version=1.0.2902.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

|     VertexBuffer(IDirect3DVertexBuffer9* pInterop) |     VertexBuffer(IntPtr unmanagedObject) |     VertexBuffer(IDirect3DVertexBuffer9* lp, Type tType, int iNumVerts, Device device, Usage usage, VertexFormats vertexFormat, Pool Pool) |     VertexBuffer(IDirect3DVertexBuffer9* lp, Device device, Usage usage, VertexFormats vertexFormat, Pool pool) |     VertexBuffer(Device device, int sizeOfBufferInBytes, Usage usage, VertexFormats vertexFormat, Pool pool) |     VertexBuffer(Type typeVertexType, int numVerts, Device device, Usage usage, VertexFormats vertexFormat, Pool pool)

Back to Contents.