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

天行健 君子當(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ì)象并獲取其接口指針,通過(guò)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操作都是通過(guò)Direct3D設(shè)備接口進(jìn)行的。比較而言,Direct3D對(duì)象更像是DirectX顯示信息的說(shuō)明,而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()把消息傳遞給窗口過(guò)程函數(shù)。

特別需要注意的是,在消息循環(huán)中使用的是PeekMessage()函數(shù),而不是GetMessage()函數(shù)。函數(shù)PeekMessage()和GetMessage()的功能大體相同,作用都是從消息隊(duì)列中取一條消息出來(lái),唯一不同的是,每當(dāng)GetMessage()發(fā)現(xiàn)消息隊(duì)列中沒有消息時(shí),過(guò)門不入,而PeekMessage()發(fā)現(xiàn)消息隊(duì)列中沒有消息時(shí),會(huì)取回系統(tǒng)控制權(quán),讓程序在此停留一段時(shí)間,應(yīng)用程序就是在這時(shí)候處理render()函數(shù)。也就是說(shuō),渲染函數(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   博問(wèn)   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>
            午夜精品久久久久久久久久久久 | 亚洲国产精品嫩草影院| 国产精品久久国产精品99gif| 欧美大片免费观看| 欧美高清在线一区二区| 欧美日韩国产色综合一二三四| 欧美激情一区三区| 国产精品萝li| 极品尤物久久久av免费看| 精品99一区二区三区| 亚洲国产高潮在线观看| 亚洲理伦在线| 亚洲欧美在线视频观看| 久久久久久久久岛国免费| 女人色偷偷aa久久天堂| 亚洲精品日本| 午夜精品视频在线观看| 美女免费视频一区| 欧美性大战久久久久久久| 国产主播喷水一区二区| 亚洲美女精品久久| 久久成人精品一区二区三区| 欧美成人性生活| 在线性视频日韩欧美| 久久久久se| 欧美性理论片在线观看片免费| 国产午夜精品美女毛片视频| 亚洲七七久久综合桃花剧情介绍| 亚洲综合三区| 亚洲高清不卡av| 亚洲精美视频| 亚洲理论在线| 国产精品亚洲一区| 亚洲高清在线观看一区| 亚洲图片欧洲图片日韩av| 久久综合给合久久狠狠狠97色69| 91久久精品国产91性色tv| 亚洲欧美综合精品久久成人| 欧美激情亚洲另类| 樱桃国产成人精品视频| 午夜影视日本亚洲欧洲精品| 亚洲黄页一区| 久久在线免费观看视频| 国产精品一区二区久久久| 夜夜嗨av一区二区三区网站四季av | 欧美国产国产综合| 欧美一区免费视频| 国产精品久久久久久av福利软件 | 999在线观看精品免费不卡网站| 久久精品免费播放| 国产一区二区精品久久| 亚洲女人天堂av| 亚洲人永久免费| 狂野欧美性猛交xxxx巴西| 国产日韩欧美一区二区| 午夜精品区一区二区三| 亚洲视频免费观看| 欧美午夜寂寞影院| 亚洲一区二区在线| 一区二区av在线| 欧美亚洲成人免费| 亚洲一区欧美一区| 亚洲一区二区三区四区五区午夜| 欧美性猛片xxxx免费看久爱| 在线一区视频| 在线视频免费在线观看一区二区| 欧美日韩在线视频观看| 亚洲伊人伊色伊影伊综合网| 国产精品99久久久久久久vr| 国产精品无人区| 久久久精品2019中文字幕神马| 久久国产精品99国产| 在线观看三级视频欧美| 亚洲丁香婷深爱综合| 欧美精品18videos性欧美| aaa亚洲精品一二三区| 99视频精品全部免费在线| 国产精品久在线观看| 久久久精品国产一区二区三区| 久久久久国产精品一区| 亚洲久色影视| 亚洲欧美中日韩| 亚洲国产精品一区制服丝袜 | 欧美激情视频免费观看| 欧美激情a∨在线视频播放| 免费h精品视频在线播放| 99国产精品国产精品久久 | 欧美日韩在线一二三| 亚洲欧美精品一区| 久久激情久久| 亚洲精品综合精品自拍| 在线亚洲成人| 在线播放国产一区中文字幕剧情欧美| 亚洲第一页自拍| 国产精品免费在线| 美女啪啪无遮挡免费久久网站| 欧美freesex交免费视频| 亚洲视频中文| 久久精品国产综合| 一本大道久久a久久精二百| 亚洲欧美国产制服动漫| 亚洲国产日韩精品| 亚洲在线视频| 99国产精品私拍| 久久福利精品| 亚洲一区二区在线看| 免播放器亚洲| 久久久精品国产一区二区三区| 欧美精品1区2区| 久久综合久久综合久久| 国产精品hd| 亚洲国产综合在线| 黄色一区二区三区四区| 中文在线一区| 在线视频精品一| 欧美成人高清视频| 乱中年女人伦av一区二区| 国产精品欧美日韩| 亚洲日本成人网| 亚洲国产一区二区三区青草影视 | 亚洲一区二区3| 欧美高清一区二区| 久久夜色精品国产欧美乱| 国产精品v欧美精品v日本精品动漫| 免费成人高清在线视频| 国产欧美日韩亚洲一区二区三区| 亚洲精品极品| 99精品视频一区| 欧美高清不卡在线| 欧美激情一级片一区二区| 一区二区视频在线观看| 久久国产精品久久久久久| 欧美一区精品| 国产欧美日韩在线视频| 亚洲小说欧美另类社区| 亚洲欧美国内爽妇网| 国产精品高清网站| 亚洲图片自拍偷拍| 午夜日韩视频| 国产日产欧产精品推荐色| 亚洲欧美日韩一区二区在线| 欧美一区二粉嫩精品国产一线天| 国产精品美女久久久浪潮软件| 制服诱惑一区二区| 欧美一区二区三区免费视频| 国产精品一区免费在线观看| 亚洲影院免费观看| 欧美中文字幕在线| 蜜臀av国产精品久久久久| 国语精品中文字幕| 久久三级福利| 亚洲国产岛国毛片在线| 一本久道久久久| 欧美日韩免费观看一区| 一区二区三区高清在线观看| 亚洲综合日韩| 一区免费视频| 欧美久久久久久久| 中文在线资源观看网站视频免费不卡| 午夜国产欧美理论在线播放| 国产日韩精品入口| 久久久午夜精品| 亚洲精品久久久一区二区三区| 亚洲一区二区三区在线看 | 99成人在线| 欧美在线高清视频| 136国产福利精品导航网址| 欧美freesex交免费视频| 日韩视频精品在线观看| 欧美一区二区视频在线观看2020| 国内外成人免费视频| 欧美高清在线视频| 欧美一区二区三区视频免费播放| 欧美jizz19hd性欧美| 一区二区三区欧美亚洲| 国产区在线观看成人精品| 欧美1区视频| 香蕉尹人综合在线观看| 亚洲成人直播| 亚洲欧美一级二级三级| 亚洲国产日韩欧美在线99| 国产精品高清一区二区三区| 久久亚洲色图| 亚洲欧美经典视频| 亚洲欧洲一区二区三区| 欧美在线综合视频| 在线亚洲观看| 亚洲国内欧美| 国内偷自视频区视频综合| 国产精品久久久久久亚洲调教| 免费成人在线视频网站| 欧美一区影院| 亚洲一区在线观看免费观看电影高清| 亚洲高清不卡在线观看| 久久综合国产精品| 久久精品视频免费播放| 在线视频中文亚洲| 亚洲黄色在线观看| 影院欧美亚洲| 国内久久婷婷综合|