Thursday, June 10, 2010

D3DX – easing the path to 2D Direct3D9

Here I’m thinking I have to create my own vertex data structure and set (or mask) the FVF (flexible vertex format) flags but it turns out that D3DX, that most wonderful of utilty libraries on top of Direct3D, has predefined several useful structs.

In my case, I’m only interested in drawing 2D shapes so D3DXVERTEX2 fits the bill.  Always nice to find a data structure that fits with the philosophy of using the least complicated data structure that’ll get the job done.  It exposes X and Y which is mostly all that I need.

2D drawing with D3DX is not unlike drawing with GDI primitives.  In GDI you select a pen into a device context, set properties of the pen then draw onto the device context with various primitives possibly changing properties as you go to achieve a different result (e.g., color, line width, etc..).

The D3DX analogue is a line (ID3DXLine).  This is created directly on a Direct3D device (which abstracts the underlying hardware in a way similar to the way a Device Context abstracts the underlying hardware in GDI).  Drawing is accomplished by setting various line properties then passing in an array of vertices representing the desired line segments.

No comments :

Post a Comment