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

天行健 君子當自強而不息

Direct3D程序設計基礎(2)

創建窗口

Direct3D是基于Microsoft Windows的圖形開發接口,它的使用必須建立在Windows窗口的基礎上,這就需要創建一個窗口,而創建窗口首先需要注冊一個窗口類。示例程序中注冊窗口類并根據窗口類創建窗口的代碼如下:

	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

創建了可供繪制圖形的窗口后,在使用Direct3D渲染圖形前,還需要進行與Direct3D相關的初始化操作,主要包括創建Direct3D對象并獲取其接口指針,通過Direct3D對象創建Direct3D設備對象。

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設備(Direct3D Device)定義了Direct3D的所有繪圖操作,絕大多數Direct3D操作都是通過Direct3D設備接口進行的。比較而言,Direct3D對象更像是DirectX顯示信息的說明,而Direct3D設備對象則是3D功能的具體實現。

要創建Direct3D設備,可調用IDirect3D9::CreateDevice()函數。

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.

 

消息循環

在Direct3D中,渲染圖形通常是在消息循環中進行的:

		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()構成,它們是Windows程序標準的消息循環處理代碼。當應用程序消息隊列中出現一條消息時,PeekMessage()返回布爾值TRUE,執行TranslateMessage()進行消息轉換,然后由DispatchMessage()把消息傳遞給窗口過程函數。

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

注意理解PeekMessage()和GetMessage()運行機制的區別,這對理解Direct3D程序中如何實現動畫是很關鍵的。


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


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美日韩日韩| 欧美日本一区二区高清播放视频| 欧美色另类天堂2015| 亚洲免费电影在线观看| 亚洲区在线播放| 欧美另类女人| 亚洲自拍偷拍色片视频| 亚洲欧美日韩另类| 黑人巨大精品欧美一区二区| 欧美成人免费网| 欧美噜噜久久久xxx| 亚洲男同1069视频| 久久国内精品视频| 亚洲欧洲日产国产网站| 一区二区三区日韩欧美精品| 国产欧美日韩另类视频免费观看| 久久久久亚洲综合| 欧美国产日韩在线观看| 亚洲欧美偷拍卡通变态| 久久婷婷人人澡人人喊人人爽| 亚洲精品国产精品国自产观看 | 99这里只有精品| 日韩一级不卡| 韩日成人av| 99精品欧美| 激情丁香综合| 中国成人亚色综合网站| 在线观看日韩av电影| 亚洲精品一区二| 国产一区二区三区av电影| 欧美激情视频网站| 国产色综合网| 一卡二卡3卡四卡高清精品视频| 国产精品亚洲精品| 亚洲欧洲免费视频| 国产一区二区0| 亚洲最新在线视频| 亚洲第一精品福利| 亚洲欧美日韩综合国产aⅴ| 亚洲免费电影在线| 久久九九精品99国产精品| 一区二区三区国产盗摄| 久久久亚洲国产美女国产盗摄| 亚洲男人的天堂在线| 欧美成人69av| 欧美aⅴ一区二区三区视频| 国产精品视频精品| 99re视频这里只有精品| 91久久久精品| 久久精品国产亚洲精品| 午夜精品视频在线| 欧美日韩中文| 亚洲毛片av在线| 亚洲另类视频| 欧美二区乱c少妇| 欧美阿v一级看视频| 国产日韩精品在线| 亚洲一区二区三区777| 亚洲视频一起| 欧美日韩一区二区在线| 亚洲精品视频中文字幕| 日韩一级大片| 欧美人与性动交cc0o| 亚洲福利视频在线| 亚洲精品乱码久久久久久| 久久人人九九| 亚洲第一福利视频| 亚洲黄一区二区| 免费毛片一区二区三区久久久| 欧美96在线丨欧| 亚洲精品视频免费在线观看| 欧美波霸影院| 亚洲国内自拍| 亚洲网在线观看| 国产精品麻豆成人av电影艾秋 | 久久久久中文| 国内精品伊人久久久久av影院 | 亚洲激情av在线| 亚洲伦理久久| 欧美日韩一二三四五区| 亚洲视频自拍偷拍| 久久精品国产综合精品| 影音先锋日韩有码| 男人插女人欧美| 亚洲欧洲一级| 午夜国产一区| 国内精品伊人久久久久av影院| 久久久久久久久岛国免费| 欧美成人一品| 99在线精品观看| 国产精品久久久久999| 欧美一区二区黄| 欧美激情一区在线观看| 在线视频亚洲一区| 国产网站欧美日韩免费精品在线观看 | 亚洲欧美日韩在线| 国产区日韩欧美| 暖暖成人免费视频| 亚洲视频在线免费观看| 美女主播精品视频一二三四| 亚洲伦理在线观看| 国产亚洲欧洲997久久综合| 蜜乳av另类精品一区二区| 一本色道久久综合亚洲精品婷婷 | 久久国产精品72免费观看| 亚洲国产精品久久久久秋霞影院| 欧美日韩成人| 久久精品30| 一区二区不卡在线视频 午夜欧美不卡在 | 国产精品美女在线| 榴莲视频成人在线观看| 亚洲午夜精品网| 亚洲黄色性网站| 久久久亚洲国产美女国产盗摄| av成人天堂| 在线观看国产一区二区| 国产精品毛片大码女人| 欧美国产另类| 老巨人导航500精品| 亚洲欧美国产视频| 99国产麻豆精品| 亚洲第一福利视频| 久久三级视频| 性欧美激情精品| 一区二区三区 在线观看视| 在线国产亚洲欧美| 国产专区欧美精品| 国产精品视频自拍| 欧美视频一区二区三区在线观看| 久久久久久婷| 久久国内精品自在自线400部| 亚洲视频国产视频| 亚洲三级免费| 亚洲国产日韩欧美综合久久| 老司机凹凸av亚洲导航| 久久久777| 久久久久久久久岛国免费| 午夜欧美视频| 欧美亚洲免费| 欧美自拍偷拍午夜视频| 亚洲欧美制服中文字幕| 亚洲欧美成人精品| 亚洲免费视频一区二区| 亚洲尤物视频在线| 香蕉国产精品偷在线观看不卡| 一区二区三区高清不卡| 在线视频精品一| 亚洲欧美日韩爽爽影院| 亚洲欧美日韩在线观看a三区| 亚洲综合成人婷婷小说| 午夜精品成人在线视频| 欧美一区二区私人影院日本 | 在线免费观看一区二区三区| 国产在线视频欧美一区二区三区| 国产一区二区三区久久 | 欧美专区第一页| 欧美在线中文字幕| 久久免费黄色| 欧美顶级大胆免费视频| 91久久精品www人人做人人爽 | 久久嫩草精品久久久精品| 久久久一区二区| 麻豆乱码国产一区二区三区| 欧美国产精品va在线观看| 91久久精品美女高潮| 99精品免费网| 午夜精品久久| 久久视频在线视频| 欧美日韩免费一区二区三区视频| 欧美视频不卡| 国产一区二区三区四区五区美女| 欲香欲色天天天综合和网| 日韩视频不卡中文| 欧美一区二区三区电影在线观看| 久久综合电影一区| 最新亚洲激情| 欧美亚洲综合久久| 欧美黄色aaaa| 国产亚洲一区二区三区在线观看 | 欧美视频你懂的| 狠狠色狠狠色综合系列| 一区二区电影免费观看| 久久av资源网站| 亚洲国产精品黑人久久久| 亚洲综合色丁香婷婷六月图片| 久久久精品日韩| 国产精品wwwwww| 亚洲人成77777在线观看网| 午夜精品久久久久久久久久久| 麻豆精品视频在线观看视频| 99精品免费| 欧美v日韩v国产v| 国产三级欧美三级| 亚洲无线观看| 欧美激情精品久久久久久| 午夜伦理片一区| 欧美视频在线一区| 亚洲欧洲一区二区三区久久| 久久久97精品| 亚洲欧美日韩在线综合|