Rookie DirectX Initialization

Source: Internet
Author: User
If a friend is looking at some of these blog, then congratulations, you will see the history of the most rotten blog about DirectX, haha, there is no understanding of the time to communicate AH.
There are too many things to tell about DirectX, like the textbooks I mentioned in my last blog, which are the Bible of the game world, and suggest that you look at the entry level. So I'm going to explain it in a note-taking.
initializing DirectX
The initialization of DirectX is divided into four steps, where only the method is listed, the specific random find a game programming books are
Create a DirectX interface
function Directx3dcreate9 (..)
Second Get device hardware information
function GetDeviceCaps
Three-filled d3dpresent_parameters structural body
This one is to define a d3dpresent_parameters structure, fill in the contents
Four Create Direct3D Device interface
function CreateDevice
This initialization of the work I will not say, and do not know how to find children's shoes I want to Demo
See, I said it was the worst technology blog in history, haha.


Some of the initialization code is posted below
Creating Direct3D Interface Objects
//--------------------------------------------------------------------------------------
Lpdirect3d9 pd3d = NULL; Creation of Direct3D interface objects
if (NULL = = pD3D = Direct3dcreate9 (d3d_sdk_version))//Initialize Direct3D interface object and make DirectX version negotiation
return E_FAIL;


Getting Hardware Device information
D3DCAPS9 caps; int flag = 0;
if (FAILED (Pd3d->getdevicecaps (D3dadapter_default, D3ddevtype_hal, &caps))
{
return E_FAIL;
}
if (Caps. Devcaps & D3ddevcaps_hwtransformandlight)
flag = d3dcreate_hardware_vertexprocessing; Supports hardware vertex operations
Else
flag = d3dcreate_software_vertexprocessing; Hardware vertex operations are not supported


Fill d3dpresent_parameters structure body
D3dpresent_parameters D3DPP;
ZeroMemory (&D3DPP, sizeof (D3DPP));
D3DPP. Backbufferwidth = window_width;
D3DPP. Backbufferheight = window_height;
D3DPP. Backbufferformat = D3DFMT_A8R8G8B8;
D3DPP. BackBufferCount = 1;
D3DPP. MultiSampleType = D3dmultisample_none;
D3DPP. multisamplequality = 0;
D3DPP. SwapEffect = D3dswapeffect_discard;
D3dpp.hdevicewindow = hwnd;
D3DPP. windowed = true;
D3DPP. EnableAutoDepthStencil = true;
D3DPP. Autodepthstencilformat = D3DFMT_D24S8;
D3DPP. Flags = 0;
D3DPP. fullscreen_refreshrateinhz = 0;
D3DPP. Presentationinterval = d3dpresent_interval_immediate;


Creating Direct3D Device Interfaces
if (FAILED pd3d->createdevice (D3dadapter_default, D3ddevtype_hal,
hwnd, VP, &D3DPP, &g_pd3ddevice))
return E_FAIL;
Safe_release (PD3D)//Release Lpdirect3d9 interface object

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.