|
Table of ContentsIntroduction - A New Graphics ArchitectureWhether porting an existing application written for DX 7, or writing a new application based on prior knowledge of DX 7, the new DirectX SDK may seem a bit daunting at first. Having ported several programs over to DirectX 8, I will attempt to relate some of my experiences here, and provide some insight into how to make the changeover as smoothly as possible. One of the most profound changes, overall, is the integration of DirectDraw with Direct3D. All access to the graphics device is now performed through the Direct3D device, rather than having a separate DirectDraw layer for 2D operations. All graphics functionality is wrapped under a single API, known as DirectX Graphics. 2D Operations under DirectX GraphicsDirectX graphics is specialized for 3D operations, and as such may appear to lack the previous support of 2D operations. However, it does provide several means to perform 2D operations. DX Graphics is structured to make use of 3D hardware acceleration, and 2D operations are thus generally performed using 3D primitives. Here is a look at the methods available for performing 2D operations under DirectX Graphics:
Exclusive Use of Flexible Vertex FormatsIn DirectX 7, support for Flexible Vertex Formats was provided, while still supplying standard vertex types for ready use. Under DirectX 8, however, all operations are based on application specified vertex formats using the FVF flags. Using Flexible Vertex Formats allows you to tailor the structure of your vertices to include only those elements that your application needs, thus reducing the memory footprint of vertex buffers as well as decreasing the bandwidth necessary to process them. However, when getting started with DX 8, or porting applications from DX 7 that use the pre-defined formats, having templates that match the previous formats is a handy starting point. You can find a set of definitions in Definitions for Standard DX7 Vertex Types, which you can use as they are or as sample templates to modify to your needs. Addition of Index BuffersJust as vertex buffers are used to avoid unnecessary copying of vertices at render time, indexes are now also packaged into lockable buffers, known as index buffers. Support is now also provided for 32 bit index values, if supported by the device, allowing the 64K vertex limit to be broken. To check for support, check the MaxVertexIndex member of D3DCAPS8. For more information on creating index buffers, see the documentation for the IDirect3DDevice8::CreateIndexBuffer() method. Drawing Primitives: Setting Streams and ShadersUnlike previous versions of the DrawPrimitive methods, in DX 8 the vertex format and source buffers for vertices and indices are set prior to rendering. The following functions are used:
For example, the following DX 7 call: lpDevice->DrawIndexedPrimitiveVB(D3DPT_TRIANGLELIST,vbuf,0,128,lpIndex,630,0); would, in DX 8, look something like this: lpDevice->SetIndices(indBuf,0); Note that the number of triangles to be rendered, rather than the number of indices used (210 vs. 630), is passed to the rendering function. Support of Non-Buffered PrimitivesThe DrawPrimitive methods in DX 8 are designed to utilize vertex buffers. To render primitives stored in arrays of vertices, the DrawPrimitiveUP() and DrawIndexedPrimitiveUP() methods are provided to support this legacy method. There are two major differences from the previous DrawPrimitive functions that should be noted:
Changes in State NamesThe naming conventions for state enumerations has changed from Direct3D 7 to DirectGraphics 8, shortening the state names :
New D3DX Library Naming ConventionsSeparate D3DX library files are now provided for release and debug builds. Release builds must link to D3DX8.LIB, and debug builds must link to D3DX8D.LIB. You can set up linking of the D3D8 and D3DX linkage in your source code, using a conditional linkage like this : #pragma comment(lib,"d3d8.lib") Note that you must also use the next D3DX8.H header file, failure to do so will result in the DX 7 headers being used. Unlike most headers in the SDK, these are version dependant. |
Visitors Since 1/1/2000:
|