1. About D3D Objects
Microsoft Direct3D COM-based objects and interfaces, the first step in Direct3D programming must be to establish this object. And after the program is finished, you must finally release the object.
2. Creating D3D Objects
In DirectX8.0, you can create a D3D object with the following code:
#include <d3dx8.h>//header files that must be included
#include <mmsystem.h>
Lpdirect3d8 g_lpd3d = NULL; D3D object pointers, which are often used later
if (NULL = = (G_lpd3d=direct3dcreate8 (d3d_sdk_version)))//D3d_sdk_version Make sure that the object is set up on the correct header file, only this value is currently available.
return E_FAIL;
Two, D3D equipment (D3D device)
The following aspects are mainly covered:
1. What is a D3D device.
A D3D device interface can be simply considered as the abstraction of a piece of graphics card, it contains all the hardware parameters and state values of the graphics card, for example, the number of video card memory and the starting linear address, whether to support depth buffer (Depth buffer), atomization (FOG), Texture (Texture) and mipmap and so on.
2. Features of the D3D device
In D3D programming, a D3D device interface is mainly capable of completing the following function modules:
A. Conversion function (transformation): mainly to complete the conversion of 3D model data, for example, world transformation, visual conversion (view transformation), projection conversion (Projection Transformation).
B. Lighting function: Complete the light rendering to the scene, for example, setting ambient light, directional light, etc.
C. rasterization display function: The 3D graphics are displayed on the screen according to some 3D state parameters and current screen display modes as well as clipping.
3. Types of D3D devices
In DirectX 8.0, three types of D3D devices are supported: Hardware abstraction layer devices, reference devices, software simulation devices, each of which can be considered as a standalone 3D driver, but each has its own uses and advantages, as detailed below.
A. Hardware abstraction Layer Device (HAL device): The most important device type in D3D, the hardware function based on the graphics card, has the fast 3D hardware acceleration function, can perform the hardware or the software vertex data processing. The disadvantage is that there must be a three-dimensional graphics card support (if you do not have enough money to buy the video card, you can only feel powerless), and, not every video card support all 3D features, so when using the device, you must often query the graphics card support features, not supported by the software device to simulate.
B. Software simulation equipment (software device): As the name implies, is a software method to simulate some of the 3D features. Depending on the specific set of CPU instructions (for example, AMD 3d-now, Intel MMX instruction set), software simulation devices can also achieve higher 3D performance. and the software simulation device has the same function interface as the hardware abstraction layer device, which is easy to use. The disadvantage is that CPU resources are heavily consumed and run slowly, and are only suitable for use with hardware abstraction layer devices.
C. Reference equipment (Reference device): A type of additional set-up supported by Microsoft Direct3D, which also relies on a special set of CPU instructions, but rather than a software simulation device, it focuses more on simulation accuracy than on speed. So it is generally applied to the test of 3D hardware and the demonstration of hardware functions.
4. Set up D3D equipment
In DirectX 8.0, the creation of a D3D device requires the use of the CreateDevice function in the IDirect3D8 interface, the function prototype is as follows
The function parameter description can query the DirectX 8.0 SDK documentation, but in English, here is a code description:
This code establishes a D3D hardware abstraction layer device based on the window program, uses the software vertex data processing, and uses a depth buffer of 16Bits.
D3ddisplaymode D3DDM;
HRESULT hr = 0;
hr = G_pd3d->getadapterdisplaymode (D3dadapter_default, &D3DDM);
if (FAILED (HR))
return E_FAIL;
D3dpresent_parameters D3DPP;
ZeroMemory (&D3DPP, sizeof (D3DPP));
D3DPP. windowed = TRUE; Indicates the window mode, not the global exclusive mode
D3DPP. SwapEffect = D3dswapeffect_discard; No swap chain required
D3DPP. Backbufferformat = D3DDM. Format; Fallback buffer color format
D3DPP. EnableAutoDepthStencil = TRUE; Make depth buffers valid
D3DPP. Autodepthstencilformat = D3dfmt_d16; Depth Buffer color format
Create the D3D Device
hr = G_pd3d->createdevice (
D3dadapter_default,//using the current graphics card as a note device
D3ddevtype_hel,//device type
HWnd,//Handle of the window where the program is located
D3dcreate_software_vertexprocessing,//processing vertex data using software methods
&D3DPP,//pointing to the structure above
&g_pd3ddevice))//pointer to 3D device
if (FAILED (HR))
{
return E_FAIL;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.