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

天行健 君子當(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>
            亚洲精品日日夜夜| 久久久欧美精品sm网站| 国产日韩一区二区三区在线播放 | 国产一区二区三区无遮挡| 欧美三区不卡| 国产精品午夜在线观看| 国产欧美一区二区精品秋霞影院| 国产精品视频久久一区| 国产综合久久久久久| 亚洲国产精品第一区二区| 亚洲激情中文1区| 日韩午夜av| 欧美在线啊v一区| 欧美~级网站不卡| 日韩午夜视频在线观看| 亚洲欧美久久| 欧美jizzhd精品欧美喷水 | 亚洲电影免费观看高清| 亚洲国产一区二区a毛片| 99热在这里有精品免费| 欧美影院成人| 亚洲国产精品t66y| 亚洲精品视频免费观看| 亚洲淫性视频| 欧美成人精品h版在线观看| 欧美揉bbbbb揉bbbbb| 雨宫琴音一区二区在线| 亚洲视频视频在线| 免费永久网站黄欧美| 亚洲调教视频在线观看| 免费成人网www| 国产日韩精品视频一区二区三区| 亚洲经典视频在线观看| 亚洲欧美中文另类| 亚洲国产欧美不卡在线观看| 性欧美video另类hd性玩具| 欧美区一区二区三区| 狠狠色综合网| 久久久久**毛片大全| 一区二区三区四区五区精品| 欧美激情第9页| 在线电影国产精品| 欧美中文字幕在线| 亚洲精品久久久久久下一站| 久久精品一本| 国内久久婷婷综合| 欧美亚洲三级| 亚洲一二区在线| 欧美无砖砖区免费| 一区二区三区视频在线观看| 欧美国产1区2区| 久久久久一区二区三区| 国产亚洲欧洲一区高清在线观看| 亚洲欧美国产毛片在线| 一区二区高清在线观看| 欧美精品一区二区三区四区| 亚洲破处大片| 欧美91视频| 裸体歌舞表演一区二区| 国产精品嫩草99av在线| 欧美一区二区三区在线免费观看| 欧美精品一区二区三区一线天视频 | 在线播放日韩专区| 久久婷婷色综合| 久久精品女人的天堂av| 黑人极品videos精品欧美裸| 久久综合网hezyo| 裸体女人亚洲精品一区| 亚洲级视频在线观看免费1级| 欧美成人四级电影| 欧美不卡高清| 亚洲少妇中出一区| 亚洲尤物视频网| 红桃视频成人| 亚洲国产另类久久久精品极度| 欧美第一黄色网| 亚洲伊人色欲综合网| 午夜在线视频观看日韩17c| 激情久久久久久| 亚洲精品1区2区| 国产精品一级| 蜜桃av一区二区| 国产精品白丝黑袜喷水久久久| 久久成年人视频| 欧美国产先锋| 亚欧成人在线| 美脚丝袜一区二区三区在线观看| 夜夜爽99久久国产综合精品女不卡 | 久久人人爽人人爽| 亚洲精品中文字幕女同| 亚洲一区视频在线| 亚洲国产欧美一区二区三区同亚洲 | 久久久99精品免费观看不卡| 欧美成人有码| 欧美在线精品一区| 欧美国产日韩在线观看| 久久国产精彩视频| 欧美福利电影在线观看| 欧美专区日韩视频| 欧美极品在线观看| 久久综合色播五月| 国产精品二区二区三区| 麻豆成人在线| 国产精品swag| 亚洲第一毛片| 国产亚洲aⅴaaaaaa毛片| 亚洲精品久久久久久久久久久久| 国产精品一区三区| 亚洲欧洲日本专区| 在线观看欧美黄色| 欧美在线观看视频一区二区三区| 亚洲一二三区视频在线观看| 欧美国产日韩亚洲一区| 日韩一区二区免费高清| 亚洲黑丝一区二区| 一本色道久久99精品综合| 亚洲午夜激情| 亚洲一区二区高清视频| 国产精品久久久久久模特| 午夜免费在线观看精品视频| 亚洲主播在线| 在线观看欧美精品| 国产精品一区二区久久久| 亚洲视频免费在线观看| 久久久久99| 亚洲网站在线| 国产女精品视频网站免费| 欧美国产日韩免费| 久久高清国产| 一区二区三区日韩精品视频| 在线观看成人av| 亚洲少妇最新在线视频| 在线一区亚洲| 亚洲精品免费电影| 国产在线一区二区三区四区| 亚洲国产精品热久久| 另类天堂视频在线观看| 欧美大尺度在线观看| 久久动漫亚洲| 国产女精品视频网站免费 | 亚洲福利免费| 国产噜噜噜噜噜久久久久久久久| 亚洲精品国产精品久久清纯直播| 亚洲精品乱码久久久久久日本蜜臀 | 在线视频免费在线观看一区二区| 欧美第一黄网免费网站| 亚洲国产成人精品女人久久久| 91久久精品国产91性色tv| 欧美—级a级欧美特级ar全黄| 亚洲精品美女在线| 亚洲精品一区二| 欧美国产日韩一区| 欧美黄污视频| 在线综合亚洲| 国产情人综合久久777777| 久久精品视频在线看| 麻豆久久精品| 亚洲精品一区在线观看| 欧美三级日本三级少妇99| 亚洲免费在线电影| 久久久亚洲一区| 亚洲精品自在久久| 国产精品成人观看视频国产奇米| 亚洲欧美清纯在线制服| 美国十次成人| 中文成人激情娱乐网| 国产日韩欧美在线视频观看| 久久婷婷蜜乳一本欲蜜臀| 亚洲美女网站| 久久性天堂网| 亚洲一级在线| 亚洲第一伊人| 国产精品免费在线| 麻豆成人小视频| 亚洲自拍偷拍网址| 亚洲福利视频网站| 欧美一进一出视频| 最新日韩中文字幕| 国产日本精品| 欧美精品啪啪| 久久av一区二区三区| 亚洲乱码国产乱码精品精98午夜 | 欧美成人免费一级人片100| 国产精品99久久久久久宅男| 在线成人激情黄色| 国产精品麻豆成人av电影艾秋| 美女成人午夜| 欧美在线关看| 亚洲女性裸体视频| 亚洲美女中文字幕| 欧美激情精品久久久久久变态| 欧美一区二区三区在线播放| 亚洲精品在线观看视频| 国产日韩欧美在线观看| 欧美日韩国产一区二区三区地区| 久久精品一区二区三区中文字幕| 亚洲天堂男人| 亚洲免费观看在线视频| 欧美激情一区二区三区全黄| 久久久久国产精品一区二区|