青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當(dāng)自強(qiáng)而不息

Direct3D程序設(shè)計(jì)基礎(chǔ)(2)

創(chuàng)建窗口

Direct3D是基于Microsoft Windows的圖形開發(fā)接口,它的使用必須建立在Windows窗口的基礎(chǔ)上,這就需要?jiǎng)?chuàng)建一個(gè)窗口,而創(chuàng)建窗口首先需要注冊(cè)一個(gè)窗口類。示例程序中注冊(cè)窗口類并根據(jù)窗口類創(chuàng)建窗口的代碼如下:

	WNDCLASSEX wc;
	wc.cbSize			= sizeof(WNDCLASSEX);
wc.style = CS_CLASSDC;
wc.lpfnWndProc = WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = inst;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = CLASS_NAME;
wc.hIconSm = NULL;
	if(! RegisterClassEx(&wc))
return -1;
	HWND hwnd = CreateWindow(CLASS_NAME, "Direct3D App", WS_OVERLAPPEDWINDOW, 200, 100, 600, 500,
NULL, NULL, wc.hInstance, NULL);
	if(hwnd == NULL)
return -1;

 

初始化Direct3D

創(chuàng)建了可供繪制圖形的窗口后,在使用Direct3D渲染圖形前,還需要進(jìn)行與Direct3D相關(guān)的初始化操作,主要包括創(chuàng)建Direct3D對(duì)象并獲取其接口指針,通過Direct3D對(duì)象創(chuàng)建Direct3D設(shè)備對(duì)象。

bool init_d3d(HWND hwnd)
{
g_d3d = Direct3DCreate9(D3D_SDK_VERSION);
	if(g_d3d == NULL)
return false;
	D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed			= TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	if(FAILED(g_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_device)))
{
return false;
}
	return true;
}

Direct3D設(shè)備(Direct3D Device)定義了Direct3D的所有繪圖操作,絕大多數(shù)Direct3D操作都是通過Direct3D設(shè)備接口進(jìn)行的。比較而言,Direct3D對(duì)象更像是DirectX顯示信息的說明,而Direct3D設(shè)備對(duì)象則是3D功能的具體實(shí)現(xiàn)。

要?jiǎng)?chuàng)建Direct3D設(shè)備,可調(diào)用IDirect3D9::CreateDevice()函數(shù)。

Creates a device to represent the display adapter.

HRESULT CreateDevice(
UINT Adapter,
D3DDEVTYPE DeviceType,
HWND hFocusWindow,
DWORD BehaviorFlags,
D3DPRESENT_PARAMETERS * pPresentationParameters,
IDirect3DDevice9 ** ppReturnedDeviceInterface
);

Parameters

Adapter
[in] Ordinal number that denotes the display adapter. D3DADAPTER_DEFAULT is always the primary display adapter.
DeviceType
[in] Member of the D3DDEVTYPE enumerated type that denotes the desired device type. If the desired device type is not available, the method will fail.
hFocusWindow
[in] The focus window alerts Direct3D when an application switches from foreground mode to background mode. See Remarks.
  • For full-screen mode, the window specified must be a top-level window.
  • For windowed mode, this parameter may be NULL only if the hDeviceWindow member of pPresentationParameters is set to a valid, non-NULL value.
BehaviorFlags
[in] Combination of one or more options that control device creation. For more information, see D3DCREATE.
pPresentationParameters

Pointer to a D3DPRESENT_PARAMETERS structure, describing the presentation parameters for the device to be created. If BehaviorFlags specifies D3DCREATE_ADAPTERGROUP_DEVICE, pPresentationParameters is an array. Regardless of the number of heads that exist, only one depth/stencil surface is automatically created.

[in, out] For Windows 2000 and Windows XP, the full-screen device display refresh rate is set in the following order:
  1. User-specified nonzero ForcedRefreshRate registry key, if supported by the device.
  2. Application-specified nonzero refresh rate value in the presentation parameter.
  3. Refresh rate of the latest desktop mode, if supported by the device.
  4. 75 hertz if supported by the device.
  5. 60 hertz if supported by the device.
  6. Device default.

An unsupported refresh rate will default to the closest supported refresh rate below it. For example, if the application specifies 63 hertz, 60 hertz will be used. There are no supported refresh rates below 57 hertz.

pPresentationParameters is both an input and an output parameter. Calling this method may change several members including:

  • If BackBufferCount, BackBufferWidth, and BackBufferHeight are 0 before the method is called, they will be changed when the method returns.
  • If BackBufferFormat equals D3DFMT_UNKNOWN before the method is called, it will be changed when the method returns.

 

ppReturnedDeviceInterface
[out, retval] Address of a pointer to the returned IDirect3DDevice9 interface, which represents the created device.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be one of the following: D3DERR_DEVICELOST, D3DERR_INVALIDCALL, D3DERR_NOTAVAILABLE, D3DERR_OUTOFVIDEOMEMORY.

Remarks

This method returns a fully working device interface, set to the required display mode (or windowed), and allocated with the appropriate back buffers. To begin rendering, the application needs only to create and set a depth buffer (assuming EnableAutoDepthStencil is FALSE in D3DPRESENT_PARAMETERS).

When you create a Direct3D device, you supply two different window parameters: a focus window (hFocusWindow) and a device window (the hDeviceWindow in D3DPRESENT_PARAMETERS). The purpose of each window is:

  • The focus window alerts Direct3D when an application switches from foreground mode to background mode (via Alt-Tab, a mouse click, or some other method). A single focus window is shared by each device created by an application.
  • The device window determines the location and size of the back buffer on screen. This is used by Direct3D when the back buffer contents are copied to the front buffer during IDirect3DDevice9::Present.

This method should not be run during the handling of WM_CREATE. An application should never pass a window handle to Direct3D while handling WM_CREATE. Any call to create, release, or reset the device must be done using the same thread as the window procedure of the focus window.

Note that D3DCREATE_HARDWARE_VERTEXPROCESSING, D3DCREATE_MIXED_VERTEXPROCESSING, and D3DCREATE_SOFTWARE_VERTEXPROCESSING are mutually exclusive flags, and at least one of these vertex processing flags must be specified when calling this method.

Back buffers created as part of the device are only lockable if D3DPRESENTFLAG_LOCKABLE_BACKBUFFER is specified in the presentation parameters. (Multisampled back buffers and depth surfaces are never lockable.)

The methods IDirect3DDevice9::Reset, IUnknown, and IDirect3DDevice9::TestCooperativeLevel must be called from the same thread that used this method to create a device.

D3DFMT_UNKNOWN can be specified for the windowed mode back buffer format when calling IDirect3D9::CreateDevice, IDirect3DDevice9::Reset, and IDirect3DDevice9::CreateAdditionalSwapChain. This means the application does not have to query the current desktop format before calling IDirect3D9::CreateDevice for windowed mode. For full-screen mode, the back buffer format must be specified.

If you attempt to create a device on a 0x0 sized window, IDirect3D9::CreateDevice will fail.

 

消息循環(huán)

在Direct3D中,渲染圖形通常是在消息循環(huán)中進(jìn)行的:

		MSG msg;
ZeroMemory(&msg, sizeof(msg));
		while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
render();
}
}

這段代碼的主要部分由PeekMessage()、TranslateMessage()和DispatchMessage()構(gòu)成,它們是Windows程序標(biāo)準(zhǔn)的消息循環(huán)處理代碼。當(dāng)應(yīng)用程序消息隊(duì)列中出現(xiàn)一條消息時(shí),PeekMessage()返回布爾值TRUE,執(zhí)行TranslateMessage()進(jìn)行消息轉(zhuǎn)換,然后由DispatchMessage()把消息傳遞給窗口過程函數(shù)。

特別需要注意的是,在消息循環(huán)中使用的是PeekMessage()函數(shù),而不是GetMessage()函數(shù)。函數(shù)PeekMessage()和GetMessage()的功能大體相同,作用都是從消息隊(duì)列中取一條消息出來,唯一不同的是,每當(dāng)GetMessage()發(fā)現(xiàn)消息隊(duì)列中沒有消息時(shí),過門不入,而PeekMessage()發(fā)現(xiàn)消息隊(duì)列中沒有消息時(shí),會(huì)取回系統(tǒng)控制權(quán),讓程序在此停留一段時(shí)間,應(yīng)用程序就是在這時(shí)候處理render()函數(shù)。也就是說,渲染函數(shù)render()都是在程序運(yùn)行時(shí)的空閑時(shí)間調(diào)用的。

注意理解PeekMessage()和GetMessage()運(yùn)行機(jī)制的區(qū)別,這對(duì)理解Direct3D程序中如何實(shí)現(xiàn)動(dòng)畫是很關(guān)鍵的。


posted on 2008-04-29 13:55 lovedday 閱讀(1272) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久久久久久性| 玖玖玖国产精品| 亚洲人午夜精品免费| 美女精品自拍一二三四| 亚洲黄色有码视频| 亚洲欧洲一区二区在线播放 | 亚洲欧美日韩精品久久久| 一本久久青青| 国产综合一区二区| 亚洲国内自拍| 国产精品白丝黑袜喷水久久久 | 在线观看91精品国产麻豆| 欧美激情国产日韩精品一区18| 免费一级欧美片在线播放| 日韩一级片网址| 亚洲欧美日韩成人高清在线一区| 国产午夜亚洲精品理论片色戒| 麻豆视频一区二区| 欧美日韩一区二区三区在线| 欧美在线视频观看| 榴莲视频成人在线观看| 在线综合+亚洲+欧美中文字幕| 亚洲欧美欧美一区二区三区| 一区二区在线观看视频| 亚洲毛片一区二区| 国产综合自拍| 日韩视频在线播放| 有码中文亚洲精品| 亚洲少妇在线| 亚洲人精品午夜| 欧美一区二区视频观看视频| 99精品久久久| 久久精品视频网| 亚洲一区三区电影在线观看| 久久久久久综合网天天| 亚洲欧美日产图| 欧美华人在线视频| 久久亚洲精品视频| 国产乱理伦片在线观看夜一区 | 亚洲免费在线观看视频| 免费日韩av| 久久婷婷蜜乳一本欲蜜臀| 欧美日韩色综合| 欧美成人精品一区二区| 国产日韩亚洲欧美| aⅴ色国产欧美| 亚洲人成人99网站| 久久激情视频免费观看| 亚洲欧美一区二区三区在线| 欧美不卡在线视频| 蜜臀久久99精品久久久画质超高清| 国产精品久久九九| 一本久久综合亚洲鲁鲁| 亚洲精品中文字| 蜜臀a∨国产成人精品| 久久嫩草精品久久久久| 国产精品专区h在线观看| 一区二区三区日韩在线观看| 99精品福利视频| 欧美理论视频| 亚洲精品久久久久久久久久久久久| 在线日韩视频| 久久人体大胆视频| 免费黄网站欧美| 伊人久久亚洲美女图片| 欧美在线国产精品| 久久综合久久综合久久综合| 国产亚洲精品aa午夜观看| 亚洲欧美日韩一区在线| 久久国产精品亚洲va麻豆| 国产欧美日韩在线视频| 欧美一区三区二区在线观看| 久久精精品视频| 国产主播精品在线| 久久天堂精品| 亚洲精品国产精品国产自| 洋洋av久久久久久久一区| 欧美日一区二区三区在线观看国产免 | 国产日韩欧美电影在线观看| 亚洲欧美中文在线视频| 久久久久国产精品厨房| 好吊一区二区三区| 老司机成人在线视频| 欧美激情影院| 亚洲午夜在线观看| 国产日产高清欧美一区二区三区| 性欧美大战久久久久久久久| 久久免费黄色| 亚洲三级免费电影| 欧美视频在线播放| 性欧美xxxx大乳国产app| 女人色偷偷aa久久天堂| 日韩视频永久免费观看| 国产精品欧美日韩| 久久成人18免费观看| 亚洲欧洲精品一区二区三区波多野1战4| 一本大道久久a久久精品综合| 国产精品视频内| 麻豆91精品| 宅男噜噜噜66国产日韩在线观看| 久久精品日韩| aⅴ色国产欧美| 国产一区二区主播在线| 欧美精品在线视频| 久久激情视频免费观看| 日韩视频三区| 另类av导航| 亚洲在线成人精品| 伊人精品成人久久综合软件| 欧美日韩亚洲高清| 久久久久久国产精品一区| 亚洲免费不卡| 欧美成人免费小视频| 午夜久久久久久久久久一区二区| 亚洲大胆人体在线| 国产欧美午夜| 欧美日韩精品高清| 久久永久免费| 久久爱www.| 亚洲一区三区电影在线观看| 欧美国产免费| 久久综合导航| 久久精品日韩一区二区三区| 亚洲一本大道在线| 亚洲另类在线视频| 亚洲国产精品传媒在线观看 | 日韩亚洲精品在线| 黄色成人小视频| 欧美日韩网址| 欧美国产欧美亚洲国产日韩mv天天看完整 | 久久久人人人| 欧美一区二区久久久| 亚洲一区精品在线| 日韩一区二区精品| 亚洲精品欧洲| 亚洲欧洲一区二区在线播放| 伊人久久久大香线蕉综合直播| 国产欧美一区二区精品性色| 欧美日韩成人一区二区| 欧美成人午夜剧场免费观看| 久久综合网色—综合色88| 欧美中文字幕在线观看| 欧美一区在线看| 久久精品国产清高在天天线| 欧美伊人久久大香线蕉综合69| 亚洲免费在线观看| 午夜久久久久久久久久一区二区| 亚洲在线观看免费视频| 午夜精品福利电影| 午夜亚洲伦理| 久久精品二区亚洲w码| 久久精品伊人| 久久综合网hezyo| 欧美电影在线观看完整版| 欧美国产极速在线| 欧美激情亚洲另类| 欧美日韩一区二区在线观看| 欧美日韩综合一区| 国产精品一二三视频| 国产综合av| 亚洲国产精品高清久久久| 亚洲精品国偷自产在线99热| 99成人在线| 午夜精品亚洲一区二区三区嫩草| 久久国产精品久久久久久| 久久偷看各类wc女厕嘘嘘偷窃| 免费不卡在线观看| 亚洲精品日本| 亚洲永久免费| 久久综合给合久久狠狠色| 欧美理论大片| 国产精品一区二区久久久久| 在线成人激情黄色| 一区二区三区国产| 久久久久久九九九九| 欧美激情第六页| 亚洲少妇诱惑| 米奇777在线欧美播放| 欧美日韩在线看| 狠狠色狠狠色综合日日91app| 91久久国产综合久久| 亚洲欧美日韩国产| 欧美成人中文| 亚洲欧美文学| 欧美精品一区在线发布| 国内激情久久| 亚洲综合欧美日韩| 欧美黄色视屏| 欧美诱惑福利视频| 国产精品videosex极品| 亚洲高清一二三区| 欧美一区二区高清在线观看| 亚洲电影第1页| 欧美诱惑福利视频| 欧美无砖砖区免费| 亚洲另类在线视频| 老鸭窝毛片一区二区三区| 亚洲一区在线视频| 欧美日韩一卡| 亚洲精品一线二线三线无人区|