Managed DirectX First Steps: Direct 3D Basics and DirectX vs. GDI+ - Referencing DirectX Libraries
(Page 3 of 14 )
When writing DirectX programs, you’ll need to add references to the DirectX libraries to your project. This can be done in one of two ways in Visual Studio: either by using the DirectX Wizard or by selecting the Add Reference option after right-clicking the project to bring up the Add Reference dialog box (see Figure 3-2).


Figure 3-2. Adding references to your project
If you’re not using Visual Studio, you can include references by using the /r: option in the command line.
Understanding Devices Having access to the adapter isn’t enough. You still want the flexibility to create multiple connections into an adapter, each one capable of handling all the fancy 3-D magic that modern graphics processors can do these days. In DirectX, that connection is called a device. Each adapter can have multiple devices, but each device is one of three different types:
- Hardware (hardware abstraction layer, or HAL): When creating HAL devices, you have direct access to the hardware acceleration features (and the resultant increase in speed). If you try to create a device of this type but have no 3-D acceleration board, DirectX will raise an error and won’t create the device.
- Reference (Reference Rasterizer): This type of device, included in the DirectX SDK, provides most of the features available for the DirectX functions, and doesn’t depend on any hardware support—everything is done in software. Although this type of device is very flexible, it’s very slow, and should only be used for debugging purposes, because it allows you to test many features not supported by your hardware. Don’t even think about creating a game with it, as the frame rate is very low—between 1 and 5 frames per second, usually.
- Software (software device): This isn’t used unless you need plug-in support for a custom renderer.
When creating a device, you must specify the adapter being used (usually the default, defined as “0” [zero]), the type of the device as described in the preceding list, the handle of the window that will be used as a viewport, and two other parameters that will define the details about the device creation, the behavior flags and the presentation parameters, as shown in the next code sample:
Direct3DDevice=new Device(Manager.Adapter,DeviceType.
Hardware,
WinHandle, CreateFlags.SoftwareVertexProcessing,
objDirect3Dpp);
The behavior flags must be one of the following flags defined by the CreateFlags enumeration:
- SoftwareVertexProcessing: This option tells DirectX that all vertex calculations will be made by software. This option is the slowest, but is always available.
- HardwareVertexProcessing: This option forces DirectX to rely on hardware capabilities to make all the vertex-processing operations. If the hardware isn’t able to perform the vertices calculation, the creation of the device will fail.
- MixedVertexProcessing: As the constant name states, this uses a mix of available hardware features and software-implemented ones to achieve the best results. If the hardware offers no vertex-processing features, this call will fail, too.
This chapter is from Beginning .NET Game Programming in C# by David Weller et. al.(Apress, 2004, ISBN: 1590593197). Check it out at your favorite bookstore today. Buy this book now.
|
Next: Put That in Your Pipeline and Shade It >>
More ASP.NET Articles
More By Apress Publishing