»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
¼¼ÊõÎĵµ > VCÎĵµ > ƽ̨SDK
DirectX ͼÐνӿÚÖ¸ÄÏ
·¢±íÈÕÆÚ£º2003-10-10 00:00:00×÷ÕߣºÒ ³ö´¦£º  

ÒëÕßÉêÃ÷£º

ÕâЩָÄÏÊÇÎÒÔÚÔĶÁ DirectX8.1 SDK ÖÐÖð²½·­Òë³öÀ´µÄ¡£¶ÔÓÚ³õ´Î½Ó´¥ DirectX Graphics µÄ±à³ÌÕ߶øÑÔ£¬ÕâÓ¦¸ÃÊǺܺõÄÉÏÊÖ×ÊÁÏ¡£Æäʵ£¬±¾È˾ÍÊÇ´ÓÕâЩָÄÏ¿ªÊ¼ÉîÈë Direct3D8.1 µÄ£»ÓÉÓÚÕâÊDZ¾È˵ÚÒ»´Î·­ÒëÓ¢ÎIJÄÁÏ£¬ÑÔÓﲻͨ£¬´Ê²»´ïÒâÖ®´¦Ò»¶¨ºÜ¶à£¬Ò»Ð©ÊõÓïÒ²ÒëµÃºÜÃãÇ¿£¬Çë¼ûÁ¡£

´ËÍ⣬ÐèҪתÔØ´ËÎÄÕߣ¬Çë±£ÁôÒÔϲ¿·Ö£º

-----------------------------------------------------------------------

DirectXͼÐνӿÚÖ¸ÄÏ ÒëÕߣºIn355Hz µç×ÓÓÊÏ䣺 In355Hz@hotmail.com

-----------------------------------------------------------------------

DirectX ͼÐνӿÚÖ¸ÄÏ£º£¨Ó¦ÓÃÓÚ DirectX 8.1 °æ C/C++ ±à³Ì£©

±¾ÇøÓòµÄÖ¸ÄϽ«ËµÃ÷ÈçºÎÔÚ C/C++ ³ÌÐòÖÐʹÓà Microsoft Direct3D ºÍ Direct3DX Íê³ÉһЩÆÕͨµÄ¹¤×÷¡£ÕâЩ¹¤×÷×ÜÊDZ»·Ö½â³ÉÈô¸É¸ö±ØÒªµÄ²½Öè¡£ÔÚijЩÇé¿öÏ£¬ÎªÁËʹ±í´ï¸üÇå³þ£¬Ò»Ð©²½Ö軹±»Ï¸·Ö³É¼¸¸ö×Ó²½Öè¡£

±¾ÇøÓòÌṩµÄÖ¸ÄÏÓУº

¡¤ Ö¸ÄÏÒ»£º´´½¨É豸

¡¤ Ö¸Ä϶þ£ºÑÝʾ¶¥µã

¡¤ Ö¸ÄÏÈý£ºÊ¹ÓþØÕó

¡¤ Ö¸ÄÏËÄ£º´´½¨ºÍʹÓùâÔ´

¡¤ Ö¸ÄÏÎ壺ʹÓÃÎÆÀíÓ³Éä

¡¤ Ö¸ÄÏÁù£ºÊ¹ÓÃMeshÄ£ÐÍ

Ìáʾ£ºÖ¸ÄÏÖгöÏÖµÄʾÀý´úÂëÀ´×ÔÓÚÿ¸öÖ¸ÄϾßÌåÌṩµÄ·¾¶ÀïµÄÔ´Îļþ¡£

ÕâЩָÄÏÖеÄÔ´´úÂëÊÇÓà C++ д³ÉµÄ¡£Èç¹ûʹÓÃC±àÒëÆ÷£¬Äã±ØÐëÊʵ±µÄ¸Ä±äÕâЩÎļþʹËüÃÇÄܹ»±àÒëͨ¹ý¡£×îÉٵģ¬ÄãÐèÒª¼ÓÈë vtable È»ºóÓÃËüÒýÓýӿں¯Êý¡£

°üº¬ÔÚʾÀý´úÂëÖеÄһЩע½â¿ÉÄÜÓëÀ´×Ô Microsoft Platform Software Development Kit (SDK) ÖеÄÔ´´úÂ벻ͬ¡£ÕâЩ¸Ä±ä½ö½öΪÁ˼ò»¯±íÊö²¢ÇÒÖ»ÏÞÓÚ×¢½âÖУ¬ÕâÑùÄܹ»·ÀֹʾÀý³ÌÐòµÄÐÐΪ±»¸Ä±ä¡£

Ö¸ÄÏÒ»£º´´½¨É豸

ΪÁËʹÓà Microsoft Direct3D£¬ÄãÊ×ÏÈÐèÒª´´½¨Ò»¸öÓ¦ÓóÌÐò´°¿Ú£¬²¢½ô½Ó×Å´´½¨ºÍ³õʼ»¯ Direct3D ¶ÔÏó¡£ÄãÓ¦¸ÃʹÓÃÕâЩ¶ÔÏóÌṩµÄ COM ½Ó¿ÚÀ´²Ù×ÝËüÃÇ£¬ÒÔ¼°´´½¨Ãè»æÒ»¸ö³¡¾°Ëù±ØÐèµÄÆäËü¶ÔÏó¡£±¾Ö¸ÄÏ°üº¬µÄ CreateDevice ʾÀý½«Àýʾ²¢ËµÃ÷ÒÔϼ¸¸ö¹¤×÷£º´´½¨ Direct3D É豸²¢ÇÒ»æÖÆÒ»¸ö¼òµ¥µÄÀ¶É«ÆÁÄ»¡£

Õâ¸öÖ¸ÄÏʹÓÃÒÔϲ½Ö裺³õʼ»¯ Direct3D£¬»æÖƳ¡¾°£¬ÒÔ¼°×îºóÇåÀíÓë¹Ø±Õ¡£

¡¤²½ÖèÒ»£º´´½¨Ò»¸ö´°¿Ú

¡¤²½Öè¶þ£º³õʼ»¯ Direct3D

¡¤²½ÖèÈý£º´¦ÀíϵͳÏûÏ¢

¡¤²½ÖèËÄ£º»æÖÆÓëÏÔʾ³¡¾°

¡¤²½ÖèÎ壺¹Ø±ÕÓëÇå³ý

×¢Ò⣺CreateDevice ʾÀý³ÌÐòµÄ·¾¶ÔÚ£º

(SDK root)\Samples\Multimedia\Direct3D\Tutorials\Tut01_CreateDevice.

²½ÖèÒ»£º´´½¨Ò»¸ö´°¿Ú

ÈκΠMicrosoft Windows ³ÌÐòÖ´ÐÐÖбØÐëÒª×÷µÄµÚÒ»¼þʾÍÊÇ´´½¨Ò»¸öÓ¦ÓóÌÐò´°¿Ú²¢½«ÆäÏÔʾ¸øÓû§¡£Îª×öµ½Õâµã£¬CreateDevice Àý³Ì½«Ê×ÏÈʵÏÖËüµÄ WinMain º¯Êý¡£ÒÔÏÂʾÀý´úÂëÍê³ÉÁË´°¿ÚµÄ³õʼ»¯¡£

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )

{

// Register the window class.

WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,

GetModuleHandle(NULL), NULL, NULL, NULL, NULL,

"D3D Tutorial", NULL };

RegisterClassEx( &wc );

// Create the application's window.

HWND hWnd = CreateWindow( "D3D Tutorial", "D3D Tutorial 01: CreateDevice",

WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,

GetDesktopWindow(), NULL, wc.hInstance, NULL );

Ç°ÊöʾÀý´úÂëÊDZê×¼µÄ Windows ±à³Ì¡£Àý×Ó¿ªÊ¼Ê±¶¨ÒåºÍ×¢²áÁËÒ»¸ö´°¿ÚÀàÃûΪ "D3D Tutorial"¡£Àà×¢²áÒÔºó£¬Ê¾Àý´úÂëʹÓÃÒÑ×¢²áµÄÀà´´½¨ÁËÒ»¸ö»ù±¾µÄ¶¥²ã£¨top-level£©´°¿Ú£¬¿Í»§ÇøÓòΪ 300 ÏñËØ¿í£¬300 ÏñÊý¸ß¡£Õâ¸ö´°¿ÚûÓв˵¥»ò×Ó´°¿Ú¡£Ê¾ÀýʹÓÃÁË WS_OVERLAPPEDWINDOW ÊôÐÔ´´½¨Ò»¸ö°üÀ¨×î´ó»¯£¬×îС»¯£¬ÒÔ¼°¹Ø±Õ°´Å¥µÄÆÕͨ´°¿Ú¡££¨Èç¹û¸ÃÀý³Ì½«ÔËÐÐÔÚÈ«ÆÁģʽÏ£¬Ê×Ñ¡µÄ´°¿ÚÊôÐÔÓ¦¸ÃÊÇWS_EX_TOPMOST£¬ËüÖ¸¶¨´´½¨µÄ´°¿ÚÖÃÓÚ²¢ÇÒ±£³ÖÔÚËùÓзÇ×î¸ß£¨non-topmost£©´°¿Ú֮ǰ£¬ÉõÖÁÔÚ´°¿Úʧ»îµÄÇé¿öÏ¡££©Ò»µ©´°¿Ú´´½¨Íê³É£¬Àý´úÂëµ÷Óñê×¼µÄ Microsoft Win32 º¯ÊýÏÔʾºÍ¸üд°¿Ú¡£

ÔÚÓ¦ÓóÌÐò´°¿Ú×¼±¸ºÃÒÔºó£¬Äã¾ÍÄÜ¿ªÊ¼ÉèÖþßÌåµÄ Microsoft Direct3D ¶ÔÏóÁË£¬

Çë¼û£º²½Öè¶þ£º³õʼ»¯ Direct3D

²½Öè¶þ£º³õʼ»¯ Direct3D

CreateDevice ʾÀýÔÚ WinMain Öд´½¨´°¿ÚÖ®ºó£¬µ÷ÓøóÌÐò¶¨ÒåµÄº¯Êý InitD3D Íê³É Microsoft Direct3D ³õʼ»¯¹ý³Ì¡£ÔÚ´´½¨´°¿ÚÖ®ºó£¬³ÌÐòÒѾ­×¼±¸ºÃ³õʼ»¯Ä㽫ÓÃÀ´»æÖƳ¡¾°µÄ Direct3D ¶ÔÏóÁË¡£Õâ¸ö¹ý³Ì°üÀ¨´´½¨Ò»¸ö Direct3D ¶ÔÏó£¬ÉèÖÃPresent Parameters£¬ÒÔ¼°×îºó´´½¨ Direct3D É豸¡£

´´½¨Íê Direct3D ¶ÔÏóÖ®ºó£¬Äã¿ÉÒÔÁ¢¼´Ê¹Óà IDirect3D8::CreateDevice ·½·¨´´½¨ Direct3D É豸¡£ÄãÒ²Äܹ»Ê¹Óà Direct3D ¶ÔÏóö¾ÙÉ豸£¬ÀàÐÍ£¬Ä£Ê½ÒÔ¼°ÆäËû¶«Î÷¡£ÕâЩ¹¤×÷µÄ´úÂë¶ÎӦλÓÚʹÓà Direct3DCreate8 º¯Êý´´½¨ Direct3D ¶ÔÏóÖ®ºó¡£

if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )

return E_FAIL;

´«µÝ¸ø Direct3DCreate8 µÄΨһ²ÎÊýÓ¦¸ÃʼÖÕÊÇ D3D_SDK_VERSION£¬Ëü¸æËß Direct3D µ±Ç°Ê¹ÓõÄÍ·ÎļþÐÅÏ¢¡£ÎÞÂÛÈçºÎ£¬Í·Îļþ»òÕßÆäËûµÄ±ä»¯½«µ¼ÖÂÕâ¸öÖµÔö¼Ó²¢Ç¿ÖÆʹÓøÃÖµµÄÓ¦ÓóÌÐòÖØбàÒë¡£Èç¹û´Ë°æ±¾²»Æ¥Å䣬µ÷Óà Direct3DCreate8 ½«Ê§°Ü¡£

ÏÂÒ»¸ö²½ÖèÊÇʹÓà IDirect3D8::GetAdapterDisplayMode ½Ó¿ÚÕÒµ½µ±Ç°µÄÏÔʾģʽ£¬´úÂëÈçÏ£º

D3DDISPLAYMODE d3ddm;

if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )

return E_FAIL;

D3DDISPLAYMODE ½á¹¹ÖÐµÄ Format ±äÁ¿½«±»ÓÃÓÚ´´½¨ Direct3D É豸¡£Èç¹ûÊÇÔËÐÐÓÚ´°¿ÚģʽϵĻ°£¬Format ²ÎÊýͨ³£ÓÃÀ´´´½¨Ò»¸öÓëÊÊÅäÆ÷µ±Ç°Ä£Ê½ÏàÆ¥ÅäµÄºó±³»º³å (Back buffer)¡£

ÔÚ¸ø D3DPRESENT_PARAMETERS ¸÷²ÎÊý¸³ÖµÊ±£¬Äã±ØÐëÖ¸¶¨ÄãµÄÓ¦ÓóÌÐòÔÚ3DϹ¤×÷µÄ·½Ê½¡£±¾ CreateDevice Àý³ÌÉèÖÃD3DPRESENT_PARAMETERS½á¹¹ÖÐ Windowed Ϊ TRUE£¬SwapEffect Ϊ D3DSWAPEFFECT_DISCARD£¬BackBufferFormat Ϊ d3ddm.Format¡£

D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory( &d3dpp, sizeof(d3dpp) );

d3dpp.Windowed = TRUE;

d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;

d3dpp.BackBufferFormat = d3ddm.Format;

×îºóÒ»²½£¬ÊÇÀûÓà IDirect3D8::CreateDevice º¯Êý´´½¨ Direct3D É豸£¬´úÂëÈçÏ£º

if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,

D3DCREATE_SOFTWARE_VERTEXPROCESSING,

&d3dpp, &g_pd3dDevice ) ) )

Ç°Êö´úÂëʹÓà D3DADAPTER_DEFAULT ±êÖ¾´´½¨ÁËÒ»¸öʹÓÃʡȱÊÊÅäÆ÷µÄÉ豸¡£Ôڷdz£¶àÊýµÄÇé¿öÏ£¬ÏµÍ³Ö»ÓÐÒ»¸öÊÊÅäÆ÷£¬³ý·ÇËü°²×°Á˶à¸öͼÐμÓËÙ¿¨¡£Í¨¹ý°Ñ DeviceType ²ÎÊýÉè³É D3DDEVTYPE_HAL£¬±íʾÄãÏ£Íû»ñµÃÒ»¸öʵ¼ÊÓ²¼þÉ豸 (hardware device) ¶ø²»ÊÇÈí¼þÐéÄâÉ豸 (software device)¡£Ê¾Àý´úÂ뻹ʹÓà D3DCREATE_SOFTWARE_VERTEXPROCESSING ±ê־֪ͨϵͳʹÓÃÈí¼þ¶¥µã´¦Àí (software vertex processing)¡£×¢Ò⣬Èç¹ûÄãÖ¸¶¨ D3DCREATE_HARDWARE_VERTEXPROCESSING ±ê־֪ͨϵͳʹÓÃÓ²¼þ¶¥µã´¦Àí (hardware vertex processing),Äã¿ÉÒÔÔÚÖ§³ÖÓ²¼þ¶¥µã´¦ÀíµÄͼÐμÓËÙ¿¨Éϵõ½´ó·ù¶ÈµÄÐÔÄÜÌáÉý¡£

ÏÖÔÚ Direct3D ÒѾ­³õʼ»¯Íê±Ï£¬ÏÂÒ»²½ÊÇÈ·±£ÄãµÄ³ÌÐò¾ßÓÐÒ»¸ö»úÖÆÓÃÀ´À´´¦ÀíϵͳÏûÏ¢£¬

¼ûÏÂÎÄ£º²½ÖèÈý£º´¦ÀíϵͳÏûÏ¢

²½ÖèÈý£º´¦ÀíϵͳÏûÏ¢

Íê³É´´½¨³ÌÐò´°¿ÚÒÔ¼°³õʼ»¯ Direct3D ÒÔºó£¬ÄãÒѾ­×¼±¸ºÃ»æÖƳ¡¾° (Render scene)¡£´ó¶àÊýÇé¿öÏ£¬Microsoft Windows ³ÌÐòÔÚËüÃǵÄÏûϢѭ»·Àï¼àÊÓϵͳÏûÏ¢£¬²¢ÇÒÔÚ¶ÓÁÐÀïûÓÐÏûϢʱ»æÖÆ»­ÃæÖ¡¡£È»¶ø£¬CreateDevice Àý³Ì½ö½öÔڵȵ½Ò»¸öWM_PAINT³öÏÖÔÚ¶ÓÁÐÀïʱ£¬²Å֪ͨӦÓóÌÐòÖػ洰¿ÚµÄËùÓв¿·Ö¡£

// The message loop.

MSG msg;

while( GetMessage( &msg, NULL, 0, 0 ) )

{

TranslateMessage( &msg );

DispatchMessage( &msg );

}

µ±Ã¿Ñ­»·Ò»´Î£¬DispatchMessage µ÷Óà MsgProc£¬ºóÕ߸ºÔð´¦Àí¶ÓÁÐÀïµÄÏûÏ¢£¬µ± WM_PAINT ÏûÏ¢½ø¶Óʱ£¬µ÷ÓøóÌÐò×ÔÉí¶¨ÒåµÄº¯Êý Render()£¬Ëü½«¸ºÔðÖػ洰¿Ú¡£È»ºó Microsoft Win32 º¯Êý ValidateRect Ö´Ðв¢½«Õû¸ö¿Í»§ÇøÓòÉèΪÓÐЧ¡£

ÏûÏ¢´¦Àíº¯ÊýµÄÀý´úÂëÈçÏ£º

LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )

{

switch( msg )

{

case WM_DESTROY:

PostQuitMessage( 0 );

return 0;

case WM_PAINT:

Render();

ValidateRect( hWnd, NULL );

return 0;

}

return DefWindowProc( hWnd, msg, wParam, lParam );

}

ÏÖÔÚ£¬Ó¦ÓóÌÐò´¦ÀíÁËϵͳÏûÏ¢£¬½Ó×ŵÄÒ»²½ÊÇ»æÖÆÏÔʾ£¬¼û£º²½ÖèËÄ£º»æÖÆÓëÏÔʾ³¡¾°

²½ÖèËÄ£º»æÖÆÓëÏÔʾ³¡¾°

ΪÁËÃè»æºÍÏÔʾÐèÒªµÄ³¡¾°£¬±¾Àý³ÌÔÚÕâÒ»²½°Ñºó±³»º³å (back buffer) Ìî³äΪÀ¶É«£¬È»ºó½«´Ëºó±³»º³åµÄÄÚÈÝ´«¸øÇ°¾°»º³å (front buffer), ²¢ÇÒ½«Ç°¾°»º³åÌá½»ÖÁÆÁÄ»¡£

Çå³ý±íÃ棬Ӧµ÷Óà IDirect3DDevice8::Clear º¯Êý£º

// Clear the back buffer to a blue color

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

Clear() ½ÓÊܵÄÇ°Á½¸ö²ÎÊý֪ͨ Microsoft Direct3D ±»Çå³ýµÄ¾ØÐÎÇøÓòÊý×éµÄ»ùÖ·ºÍ´óС£¬¸Ã¾ØÐÎÇøÓòÊý×éÃèÊöÁË»æÖÆÄ¿±ê±íÃæ (render target surface) ÀïÐèÒªÇå³ýµÄÇøÓò¡£

ÔÚ´ó¶àÊýÇé¿öÏ£¬Ö»Ê¹Óõ¥¸ö¾ØÐθ²¸ÇÕû¸ö»æÖÆÄ¿±ê±íÃæ¡£ÕâÑùÄãÖ»ÐèÉèÖõÚÒ»¸ö²ÎÊýΪ 0 ¼°µÚ¶þ¸ö²ÎÊýΪ NULL¡£µÚÈý¸ö²ÎÊý½«¾ö¶¨·½·¨µÄÐÐΪ£¬Äã¿ÉÒÔͨ¹ýÉèÖÃÌض¨µÄ±êÖ¾ÓÃÀ´Çå³ý»æÖÆÄ¿±ê±íÃæ (render target surface)£¬¹ØÁªµÄZ»º³å (associated depth buffer)£¬Ä£°æ»º³å (stencil buffer)£¬ÒÔ¼°ÈÎÒâÕâÈýÕߵĻìºÏ¡£±¾Ö¸Äϲ»Ê¹ÓÃZ»º³å£¬ËùÒÔ½ö½öʹÓÃÁË D3DCLEAR_TARGET ±êÖ¾¡£×îºóÈý¸ö²ÎÊý·Ö±ðÓÃÓÚÉèÖöÔÓ¦»æÖÆÄ¿±ê±íÃæ¡¢Z»º³åºÍÄ£°æ»º³åµÄÇå³ýÌî³äÖµ (reflect clearing values)¡£¸Ã CreateDevice Àý³Ì½«»æÖÆÄ¿µÄ±íÃæµÄÇå³ýÌî³äÉ«ÉèÖÃΪÀ¶É« (D3DCOLOR_XRGB(0,0,255)¡£ÓÉÓÚÏàÓ¦µÄ±ê־ûÓÐÉèÖã¬×îºóÁ½¸ö²ÎÊý±» Clear() ºöÂÔ¡£

ÔÚÇå³ýÁËÊÓ¿Ú (viewport) Ö®ºó£¬CreateDevice Àý³Ì¸æÖª Direct3D »æͼ½«Òª¿ªÊ¼£¬È»ºóÁ¢¼´Í¨ÖªÕâ´Î»æÖÆÍê³É£¬¼ûÒÔÏ´úÂë¶Î£º

// Begin the scene.

g_pd3dDevice->BeginScene();

// Rendering of scene objects happens here.

// End the scene.

g_pd3dDevice->EndScene();

µ±»æÖÆ¿ªÊ¼»òÍê³Éʱ£¬IDirect3DDevice8::BeginScene ºÍ IDirect3DDevice8::EndScene º¯Êý½«ÓÃÐźÅ֪ͨϵͳ¡£ÄãÖ»ÄÜÔÚÕâÁ½º¯ÊýÖ®¼äµ÷ÓÃÆäËüµÄ»æͼº¯Êý¡£¼´Ê¹µ÷Óûæͼº¯Êýʧ°Ü£¬ÄãÒ²Ó¦¸ÃÔÚÖØе÷Óà BeginScene ֮ǰµ÷Óà EndScene¡£

»æÖÆÍêÖ®ºó£¬µ÷Óà IDirect3DDevice8::PresentÏÔʾ¸Ã³¡¾°£º

g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

Present() ½ÓÊܵÄÇ°Á½¸ö²ÎÊýÊÇԭʼ¾ØÐκÍÄ¿±ê¾ØÐΡ£ÔÚÕâÒ»²½£¬Àý³ÌÉèÖÃÕâÁ½¸ö²ÎÊýΪ NULL ²¢°ÑÕû¸öºó±¸»º³åÌá½»µ½Ç°¾°»º³å¡£µÚÈý¸ö²ÎÊýÓÃÓÚÉèÖøôÎÌá½»µÄÄ¿±ê´°¿Ú¡£ÒòΪÕâ¸ö²ÎÊý±»ÉèΪ NULL£¬Êµ¼ÊʹÓõĴ°¿ÚÊÇ D3DPRESENT_PARAMETERS µÄ hWndDeviceWindow ³ÉÔ±¡£µÚËĸöÊÇ DirtyRegion ²ÎÊý£¬ÔÚ¾ø´ó¶àÊýÇé¿öÏÂÓ¦¸ÃÉèΪ NULL¡£

±¾Ö¸ÄϵÄ×îÖÕ²½ÖèÊǹرÕÓ¦ÓóÌÐò£¬¼û£º²½ÖèÎ壺¹Ø±ÕÓëÇå³ý

²½ÖèÎ壺¹Ø±ÕÓëÇå³ý

ÔÚÖ´ÐеÄÈô¸Éʱ¿Ì£¬ÄãµÄÓ¦ÓóÌÐò±ØÐëÁ¢¼´¹Ø±Õ¡£¹Ø±ÕÒ»¸ö Direct3D Ó¦ÓóÌÐòÖв»Ö»ÊÇÒâζ×ÅÄã±ØÐëÏú»Ù³ÌÐò´°¿Ú£¬²¢ÇÒÄ㻹ҪÊͷųÌÐòÖÐʹÓùýµÄµÄÈκΠDirect3D ¶ÔÏó²¢ÇÒÎÞЧ»¯ËüÃǵÄÖ¸Õë¡£µ±ÊÕµ½Ò»¸ö WM_DESTROY ÏûϢʱ£¬CreateDevice Àý³Ìͨ¹ýµ÷ÓÃÒ»¸ö±¾µØ¶¨ÒåµÄº¯Êý Cleanup() À´´¦ÀíÕâЩ¹¤×÷¡£

VOID Cleanup()

{

if( g_pd3dDevice != NULL)

g_pd3dDevice->Release();

if( g_pD3D != NULL)

g_pD3D->Release();

}

ÉÏÊöº¯Êý¶Ôÿ¸ö¶ÔÏóµ÷Óà IUnknown::Release ·½·¨À´ÊÍ·ÅËüÃÇ×ÔÉí¡£ÓÉÓÚDirectX×ñÑ­ COM ¹æÔò£¬´ó¶àÊý¶ÔÏóµ±ÆäÒýÓüÆÊý½µÎª0ʱ£¬DirectX»á×Ô¶¯µÄ´ÓÄÚ´æÖÐÊÍ·ÅÕâ¸ö¶ÔÏó¡£

¶ÔÓÚÆäËû¹Ø±Õ³ÌÐòÇé¿ö£¬¿ÉÄÜ·¢ÉúÔÚ³ÌÐòµÄƽ³£Ö´ÐÐÖСª¡ª±ÈÈçÓû§¸Ä±äÁË×ÀÃæµÄ²ÎÊý»òÉ«É¡ª´ËʱÄã¿ÉÄÜÐèÒª³·ÏúºÍÖؽ¨Ê¹ÓÃÖÐµÄ Microsoft Direct3D ¶ÔÏó¡£Òò´ËÒ»¸öºÃµÄÖ÷Òâ¾ÍÊǽ«ÄãµÄÊÍ·Å´úÂë·Åµ½Ò»Æð£¬ÒÔ±ãÄÜÔÚÐèҪʱËæʱµ÷ÓÃËü¡£

±¾Ö¸ÄÏÒѾ­ËµÃ÷ÁËÈçºÎ´´½¨Ò»¸öÉ豸£¬Ö¸Ä϶þ£ºÑÝʾ¶¥µã(Render Vertex) £¬½«¸æËßÄãÈçºÎÓö¥µã£¨Vertex£©´´½¨¼¸ºÎÐÎÌå¡£

Ö¸Ä϶þ£ºÑÝʾ¶¥µã(Render Vertex)

Microsoft Direct3D дµÄÓ¦ÓóÌÐòʹÓö¥µã(Vertex)¹¹Ô켸ºÎÎïÌ塣ÿһ¸öÈýά¿Õ¼ä (3D) ³¡¾°°üÀ¨Ò»¸ö»ò¼¸¸öÕâÑùµÄ¼¸ºÎÎïÌå¡£Vertices Àý³Ì¹¹Ôì¼òµ¥µÄÎïÌ壬һ¸öÈý½ÇÐΣ¬²¢ÇÒ½«Ëü»æÖƵ½ÏÔʾÆÁÉÏ¡£

±¾Ö¸ÄÏ˵Ã÷ÈçºÎ²ÉÓÃÒÔϲ½Öè´Ó¶¥µã¹¹ÔìÒ»¸öÈý½ÇÐΣº

¡¤µÚÒ»²½£º¶¨ÒåÒ»¸ö×Ô¶¨Ò嶥µãÀàÐÍ

¡¤µÚ¶þ²½£ºÉèÖö¥µã»º³å

¡¤µÚÈý²½£º»æÖÆÖÁÏÔʾÆÁ

×¢Ò⣺Vertices ʾÀý³ÌÐòµÄ·¾¶Îª£º

(SDK root)\Samples\Multimedia\Direct3D\Tutorials\Tut02_Vertices.

Vertices ³ÌÐòµÄʾÀý´úÂëÓë CreateDevice µÄ´úÂë´ó²¿·ÖÏàͬ¡£±¾¡°ÑÝʾ¶¥µã£¨Render Vertex£©¡±Ö¸ÄϽö½ö¹Ø×¢ÓÚÄÇЩ¶ÀÌصģ¬¹ØÓÚ¶¥µãµÄ´úÂë¶ø²»°üÀ¨³õʼ»¯ Direct3D£¬´¦Àí Microsoft Windows ÏûÏ¢£¬»æͼ£¬ÓëÇåÀíµÈ¹¤×÷¡£ÈçÒªµÃµ½ÓйØÕâЩÈÎÎñµÄÐÅÏ¢£¬Çë²Î¿¼ Ö¸ÄÏÒ»£º´´½¨É豸¡£

µÚÒ»²½£º¶¨ÒåÒ»¸ö×Ô¶¨Ò嶥µãÀàÐÍ

Vertices Àý³ÌʹÓÃÈý¸ö¶¥µã¹¹ÔìÒ»¸ö 2D µÄÈý½ÇÐΡ£ÕâÀïÌá¼°Á˶¥µã»º³åµÄ¸ÅÄÕâÊÇÓÃÓÚ±£´æºÍÑÝʾ´óÁ¿¶¥µãµÄ Microsoft Direct3D ¶ÔÏó¡£Í¨¹ýÖ¸¶¨Ò»¸ö×Ô¶¨ÒåµÄ¶¥µã½á¹¹ºÍÏàÓ¦µÄ¿É±äÏòÁ¿¸ñʽ (FVF)£¬¶¥µãÄܹ»²ÉÓúܶ෽·¨¶¨Òå¡£±¾ Vertices Àý³ÌʹÓõĶ¥µã¸ñʽ¶¨ÒåÓÚÒÔÏ´úÂëƬ¶ÏÖС£

struct CUSTOMVERTEX

{

FLOAT x, y, z, rhw; // The transformed position for the vertex.

DWORD color; // The vertex color.

};

ÉÏÃæµÄ½á¹¹Ìå˵Ã÷ÁË×Ô¶¨Ò嶥µãÀàÐ͵ĸñʽ¡£ÏÂÒ»²½ÊǶ¨Òå FVF ÒÔÃèÊö¶¥µã»º³åÇøÖеĶ¥µãÄÚÈÝ¡£ÒÔÏ´úÂëƬ¶Î¶¨ÒåÁËÒ»¸ö FVF ²¢·ûºÏ´ËÉϽ¨Á¢µÄ×Ô¶¨Ò嶥µãÀàÐÍ¡£

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

¿É±ä¶¥µã¸ñʽ±ê¼ÇÃèÊöÁËʹÓÃÖеÄ×Ô¶¨Ò嶥µãÀàÐÍ¡£Ç°ÊöʾÀý´úÂëʹÓÃÁË D3DFVF_XYZRHW ºÍ D3DFVF_DIFFUSE ±êÖ¾£¬Õ⽫¸æË߶¥µã»º³å£¬×Ô¶¨Ò嶥µãÀàÐÍ°üº¬Ò»×éת»»¹ýµÄµã×ø±ê²¢½ô¸ú×ÅÒ»¸öÑÕÉ«²ÎÊý¡£

ÏÖÔÚ×Ô¶¨ÒåÏòÁ¿¸ñʽºÍ FVF ÒѾ­±»Ö¸¶¨ºÃÁË£¬ÏÂÒ»²½½«Ê¹Óö¥µãÌî³ä¶¥µã»º³åÇø£¬Çë²Î¿´£ºµÚ¶þ²½£ºÉèÖö¥µã»º³å ¡£

×¢Ò⣺Vertices Àý³ÌÖеĶ¥µãÊÇת»»¹ýµÄ¡£ÓÃÁíÒ»¾ä»°Ëµ£¬ËüÃÇÒѾ­ÔÚ 2D ´°¿Ú×ø±êϵÏ¡£ÕâÒâζ×Å×ù±êµã (0,0) λÓÚ×óÉϽǣ¬ÇÒÕýµÄ x °ëÖáÏòÓÒ£¬ÕýµÄ y °ëÖáÏòÏ¡£ÕâЩ¶¥µãͬÑùÒ²ÊǹâÕÕ¹ýµÄ£¬Õâ˵Ã÷ËüÃǵÄ×ÅÉ«²»Í¨¹ý Direct3D ÕÕÃ÷¶øÓÉËüÃÇ×Ô¼ºµÄÑÕÉ«´úÌæ¡£

µÚ¶þ²½£ºÉèÖö¥µã»º³å

ÏÖÔÚ×Ô¶¨Ò嶥µã¸ñʽÒѾ­Íê³É£¬³õʼ»¯¶¥µãµÄʱºòµ½ÁË¡£ Vertices Àý³Ì´´½¨Á˱ØÐèµÄ Microsoft Direct3D ¶ÔÏóÖ®ºóµ÷Óñ¾³ÌÐòÄÚ²¿¶¨ÒåµÄº¯Êý InitVB() ½øÐÐÕâ¸ö¹¤×÷¡£ÒÔÏ´úÂë¶Î½«³õʼ»¯Èý¸ö×Ô¶¨Ò嶥µãµÄÖµ¡£

CUSTOMVERTEX g_Vertices[] =

{

{ 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color

{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },

{ 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },

};

Ç°Êö´úÂëƬ¶Î²ÉÓÃÈý½ÇÐεÄÈý¸ö¶¥µãÌî³äÈý¸öVertex²¢Ö¸¶¨ÁËÿ¸ö¶¥µãµÄÉ¢Éä¹âµÄÑÕÉ«¡£µÚÒ»¸ö¶¥µãλÓÚ (150,50) £¬É¢ÉäºìÉ« (0xffff0000)¡£µÚ¶þ¸ö¶¥µãλÓÚ (250,250) £¬ÎªÂÌÉ« (0xff00ff00)¡£µÚÈýµãλÓÚ (50,250) ²¢É¢ÉäÀ¶ÂÌÉ« (0xff00ffff)¡£Ã¿Ò»µã¶¼¾ßÓÐÏàͬµÄ 0.5 ZÖµ¼° 1.0 µÄ RHW ²ÎÊý¡£¹ØÓÚÕâЩʸÁ¿¸ñʽµÄÆäËüÐÅÏ¢¼û SDK: Transformed and Lit Vertices¡£

ÏÂÒ»²½½«µ÷Óà IDirect3DDevice8::CreateVertexBuffer ´´½¨¶¥µã»º³åÇø£¬ÈçÒÔÏ´úÂë¶ÎËùʾ£º

if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),

0 /* Usage */, D3DFVF_CUSTOMVERTEX,

D3DPOOL_DEFAULT, &g_pVB ) ) )

return E_FAIL;

CreateVertexBuffer µÄÍ·Á½¸ö²ÎÊý¸æËß Direct3D ж¥µã»º³åÇøÔ¤¼ÆµÄ´óСºÍÓ÷¨¡£½ô¸úµÄÁ½¸ö²ÎÊýÖ¸¶¨Ð»º³åÇøµÄʸÁ¿¸ñʽ¼°´æ´¢Î»Öá£ÕâÀïµÄÏòÁ¿¸ñʽÊÇ D3DFVF_CUSTOMVERTEX£¬¾ÍÊÇÀý³ÌÏÈÇ°¶¨ÒåµÄ FVF Öµ¡£D3DPOOL_DEFAULT ±ê¼Ç¸æËß Direct3D ÔÚ×îºÏÊʵÄλÖô´½¨´Ë¶¥µã»º³åÇø¡£×îºóÒ»¸ö²ÎÊý·µ»Ø´´½¨Íê³ÉµÄ¶¥µã»º³åÇø¶ÔÏóµØÖ·¡£

´´½¨Á˶¥µã»º³åÇøÖ®ºó£¬ÈçÒÔÏ´úÂë¶ÎËùʾ£¬¿ªÊ¼²ÉÓÃ×Ô¶¨Òå¸ñʽµÄ¶¥µãÌî³ä»º³åÇøÖеÄÊý¾Ý¡£

VOID* pVertices;

if( FAILED( g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 ) ) )

return E_FAIL;

memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );

g_pVB->Unlock();

Ê×Ïȵ÷Óà IDirect3DVertexBuffer8::Lock Ëø¶¨¶¥µã»º³åÇø¡£º¯ÊýµÚÒ»¸ö²ÎÊýÊÇËø¶¨¶¥µãÊý¾ÝµÄÆ«ÒÆÁ¿£¬°´×Ö½Ú¼ÆËã¡£µÚ¶þ¸ö²ÎÊýÊÇÐèËø¶¨µÄ¶¥µãÊý¾Ý³¤¶È£¬Í¬Ñù°´×Ö½Ú¼ÆËã¡£µÚÈý¸ö²ÎÊýÊÇÒ»¸ö BYTE ÀàÐÍÖ¸ÕëµÄµØÖ·£¬ÓÃÓÚ·µ»ØÖ¸Ïò¶¥µãÊý¾ÝµÄµØÖ·¡£µÚËĸö²ÎÊý¸æÖª¶¥µã»º³åÇøÈçºÎËø¶¨Êý¾Ý¡£

ͨ¹ýʹÓà memcpy£¬¶¥µã±»¸´ÖƵ½¶¥µã»º³åÇøÀï¡£½«¶¥µã·ÅÈ뻺³åÇøÖ®ºó£¬µ÷ÓÃÒ»´Î IDirect3DVertexBuffer8::Unlock ÒÔ½âËø¶¥µã»º³åÇø¡£Õâ¸öËø¶¨¡ª¡ª½âËø»úÖÆÊDZØÐèµÄ£¬ÒòΪÕýÔÚʹÓõĶ¥µã»º³åÇø¿ÉÄÜλÓÚÉ豸ÄÚ´æÖС£

ÏÖÔÚ¶¥µã»º³åÇøÒѾ­ÌîÈ붥µã£¬»æÖƵ½ÏÔʾµÄʱºòµ½ÁË£¬¼ûÃèÊö£ºµÚÈý²½£º»æÖÆÖÁÏÔʾÆÁ ¡£

µÚÈý²½£º»æÖÆÖÁÏÔʾÆÁ

ÏÖÔÚ»º³åÇøÒѾ­ÌîÈ붥µã£¬ÏÖÔÚÐèÒª°ÑËü»æÖƵ½ÏÔʾÆÁÉÏ¡£ÔÚ»æÖƵ½ÆÁĻ֮ǰ£¬ÏȽ«±³¾°Çå³ýΪÀ¶É«²¢µ÷Óà BeginScene¡£

g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0L );

g_pd3dDevice->BeginScene();

´Ó¶¥µã»º³åÇø»æÖƶ¥µãÊý¾ÝÐèҪһЩ²½Öè¡£Ê×ÏÈ£¬ÄãÐèÒªÉèÖÃÁ÷Êý¾ÝÔ´£»ÔÚµ±Ç°Çé¿öÏ£¬Ê¹ÓÃµÚ 0 ¸öÁ÷ ¡£Á÷µÄÊý¾ÝÔ´ÊÇͨ¹ýµ÷Óà IDirect3DDevice8::SetStreamSource ÉèÖõġ£

g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );

SetStreamSource µÄµÚÒ»¸ö²ÎÊý¸æËß Microsoft Direct3D É豸ÉèÖÃÊý¾ÝÁ÷µÄË÷Òý¡£µÚ¶þ¸ö²ÎÊýÊÇ°ó¶¨ÔÚ¸ÃÊý¾ÝÁ÷ÉϵĶ¥µã»º³åÇø¡£µÚÈý¸ö²ÎÊýÊÇÊý¾Ýµ¥ÔªµÄ´óС£¬ÓÃ×Ö½ÚÊý±íʾ¡£ÔÚÉÏÃæµÄʾÀý´úÂëÖУ¬½«Ê¹ÓÃCUSTOMVERTEX µÄ´óС×÷ΪÊý¾Ýµ¥ÔªµÄ´óС¡£

ÏÂÒ»²½Í¨¹ýµ÷Óà IDirect3DDevice8::SetVertexShader ʹ Direct3D Á˽âʹÓÃÖеĶ¥µã´¦ÀíÆ÷£¨Vertex Shader£©¡£¾ÍÕûÌå¶øÑÔ£¬×Ô¶¨Ò嶥µã´¦ÀíÆ÷ÊÇÒ»Öָ߼¶µÄ»°Ì⣬µ«ÊÇÔÚ¾ø´ó¶àÊýÇé¿ö϶¥µã´¦ÀíÆ÷½ö½öµÈÓÚ FVF ´úÂë¡£ÕâÄܹ»Èà Direct3D ÖªµÀ´¦ÀíÖеĶ¥µãÀàÐÍ¡£ÒÔÏ´úÂëƬ¶Î½«FVFÉèÖÃΪµ±Ç°¶¥µã´¦ÀíÆ÷£º

g_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );

SetVertexShader() ΨһµÄ²ÎÊýÊǵ±Ç°ÉèÖõĶ¥µã´¦ÀíÆ÷µÄ¾ä±ú¡£Õâ¸ö²ÎÊýµÄÖµ¿ÉÒÔÊÇ´ÓIDirect3DDevice8::CreateVertexShader ·µ»ØµÄ¾ä±ú£¬»òÕßÊÇ FVF ´úÂë¡£ÔÚÕâ¶ù£¬Ê¹ÓõIJÎÊýÊǶ¨ÒåΪ D3DFVF_CUSTOMVERTEX µÄ FVF ´úÂë¡£

¹ØÓÚ¶¥µã´¦ÀíÆ÷µÄ¸ü¶àÐÅÏ¢£¬Çë¼û SDK: Vertex Shader Ò»Õ¡£

ÏÂÒ»²½Ê¹Óà IDirect3DDevice8::DrawPrimitive »æÖƶ¥µã»º³åÇøÖеĶ¥µã£¬¼ûÒÔÏ´úÂëƬ¶Î£º

g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );

DrawPrimitive ½ÓÊܵĵÚÒ»¸ö²ÎÊýÊÇÒ»¸ö±ê¼Ç£¬Ëü֪ͨ Direct3D »æÖÆÄÄÖÖÀàÐ͵ÄÎï¼þ(Primitive)¡£±¾Àý³ÌʹÓà D3DPT_TRIANGLELIST ±ê¼ÇÖ¸¶¨ÎªÈý½ÇÐÎÐòÁС£µÚ¶þ¸ö²ÎÊýÊǵÚÒ»¸ö¶¥µãµÄË÷Òý¡£µÚÈý¸ö²ÎÊý֪ͨ»æÖƵÄÎï¼þµÄÊýÄ¿¡£±¾Àý×ÓÖ»»­Ò»¸öÈý½ÇÐΣ¬Õâ¸öֵΪ 1¡£

¹ØÓÚ²»Í¬ÖÖÀàÎï¼þµÄ¸ü¶àÐÅÏ¢£¬¿É¼û SDK: 3-D Primitive

×îºóµÄÒ»²½ÊǽáÊø³¡¾°²¢Á¢¼´½«ºó±³»º³åÌύΪǰ¾°»º³å¡£ÕâЩдÔÚÒÔÏ´úÂëƬ¶ÎÖУº

g_pd3dDevice->EndScene();

g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

µ±ºó±³»º³å±»ÌύΪǰ¾°»º³åºó£¬¿Í»§´°¿Ú½«ÏÔʾ³öÒ»¸öÈý¸öµãÑÕÉ«¸÷ÒìµÄÈý½ÇÐΡ£

±¾Ö¸ÄÏÒѾ­Ö¸µ¼ÄãÈçºÎʹÓö¥µã¹¹Ô켸ºÎÍâÐÎÁË¡£Ö¸ÄÏÈý£ºÊ¹ÓþØÕó ½«½éÉܾØÕóµÄ¸ÅÄîÒÔ¼°ÈçºÎʹÓÃËüÃÇ¡£

Ö¸ÄÏÈý£ºÊ¹ÓþØÕó

±¾Ö¸ÄϽéÉܾØÕóµÄ¸ÅÄî¼°ÑÝʾÈçºÎʹÓÃËüÃÇ¡£Vertices Àý³Ìͨ¹ý³ÊµÝ2DµÄ¶¥µã»­³öÁËÒ»¸öÈý½ÇÐΡ£È»¶ø£¬ÔÚÕâ¸öÖ¸ÄÏÖУ¬Ä㽫ͨ¹ý¶¥µã±ä»»ÔÚ 3-D »·¾³Ï¹¤×÷¡£¾ØÕóºÍ±ä»»Ò²Í¬ÑùÓÃÓÚÉèÖÃÉãÓ°Í·ÓëÊÓ¿Ú£¨Viewport£©¡£

ÔÚ Matrices Àý³Ì³ÊµÝ¼¸ºÎÎïÌå֮ǰ£¬Ëüµ÷ÓóÌÐò×Ô¶¨Ò庯Êý SetupMatrices ´´½¨²¢ÉèÖÃÓÃÓÚÑÝʾ 3-D Èý½ÇÐεľØÕó±ä»»¡£×÷Ϊ´ú±í£¬ÈýÖÖÀàÐ͵ı任ͬʱ±»ÉèÖõ½Ò»¸ö 3-D ³¡¾°¡£´´½¨ÕâЩµäÐͱ任µÄ²½ÖèÈçÏÂ±í£º

¡¤µÚÒ»²½£º¶¨ÒåÊÀ½ç±ä»»¾ØÕó

¡¤µÚ¶þ²½£º¶¨Òå¹Û²ì±ä»»¾ØÕó

¡¤µÚÈý²½£º¶¨ÒåÓ³Éä±ä»»¾ØÕó

×¢Ò⣺Matrices ʾÀý³ÌÐòµÄ·¾¶Îª£º

(SDK root)\Samples\Multimedia\Direct3D\Tutorials\Tut03_Matrices.

´´½¨ÕâÈýÖֱ任µÄ˳Ðò²¢²»Ó°Ï쳡¾°ÔªËصÄÊä³ö¡£ÎÞÂÛÈçºÎ£¬Direct3D ¶¼Ê¹ÓÃÒÔÏÂ˳ÐòÒÀ´Î½«¾ØÕó×÷ÓÃÓÚ³¡¾°£º(1) ÊÀ½ç£¬(2) ¹Û²ì£¬(3) Ó³Éä¡£

Matrices ¹¤³ÌµÄʾÀý´úÂ뼸ºõÓë Vertices ¹¤³ÌµÄ´úÂëÏàͬ¡£¸Ã¡°Ê¹ÓþØÕó¡±Ö¸ÄϽö½ö¹Ø×¢ÄÇЩÓйؾØÕóµÄ¶ÀÌØ´úÂ룬¶ø²»Öظ´³õʼ»¯ Direct3D£¬´¦Àí Microsoft Windows ÏûÏ¢£¬ÑÝʾ£¬ÒÔ¼°Çå³ý¡£¹ØÓÚÕâЩ¹¤×÷µÄÐÅÏ¢£¬Çë¼û Ö¸ÄÏÒ»£º´´½¨É豸 ¡£

±¾Ö¸ÄÏʹÓÃ×Ô¶¨Ò嶥µã¸ñʽºÍµ¥¸ö¶¥µã»º³åÇø³ÊµÝ¼¸ºÎÄ£ÐÍ£¬¹ØÓÚ¸ü¶àµÄÓйØÑ¡Ôñ×Ô¶¨Ò嶥µãÀàÐÍÒÔ¼°Ö´Ðж¥µã»º³åÇøµÄÐÅÏ¢£¬¼û Ö¸Ä϶þ£ºÑÝʾ¶¥µã ¡£

µÚÒ»²½£º¶¨ÒåÊÀ½ç±ä»»¾ØÕó£¨World Transformation Matrix£©

ÊÀ½ç±ä»»¾ØÕó¶¨ÒåÁËÔõÑùת»»¡¢Ëõ·Å¡¢ÒÔ¼°Ðýת 3-D Ä£Äâ¿Õ¼äÖеļ¸ºÎÎïÌå¡£

ÒÔÏ´úÂëƬ¶ÎΪ Microsoft Direct3D É豸ÉèÖõ±Ç°µÄÊÀ½ç±ä»»²¢ÇÒʹÈý½ÇÐÎÈÆ y-Öá Ðýת¡£

D3DXMATRIX matWorld;

D3DXMatrixRotationY( &matWorld, timeGetTime()/150.0f );

g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

µÚÒ»²½ÊÇͨ¹ýµ÷Óà D3DXMatrixRotationY º¯ÊýʹÈý½ÇÐÎÈÆ y-Öá Ðýת¡£º¯ÊýµÚÒ»¸ö²ÎÊýÊÇÖ¸Ïò D3DMATRIX ½á¹¹µÄÖ¸ÕëÓÃÓÚ·µ»Ø²Ù×÷½á¹û¡£µÚ¶þ¸ö²ÎÊýÊÇÒÔ»¡¶È±íʾµÄÐýת½Ç¶È¡£

ÏÂÒ»²½Êǵ÷Óà IDirect3DDevice8::SetTransform ¸ø Direct3D É豸ÉèÖÃÊÀ½ç±ä»»¡£SetTransform ½ÓÊܵĵÚÒ»¸ö²ÎÊý֪ͨ Direct3D ±»ÉèÖõÄÊÇÄĸöת»»¡£Õâ¸öÀý×ÓÓà D3DTS_WORLD ºêÖ¸¶¨±»ÉèÖõÄÊÇÊÀ½ç±ä»»¡£µÚ¶þ¸ö²ÎÊýÊÇÒ»¸öÖ¸Ïò±»ÉèΪµ±Ç°±ä»»Ö®¾ØÕóµÄÖ¸Õë¡£

¹ØÓÚÊÀ½ç±ä»»µÄ¸ü¶àÐÅÏ¢£¬¼û£ºSDK: World Transformation

¶¨ÒåÍ곡¾°µÄÊÀ½ç±ä»»ºó£¬Äã¿ÉÒÔ×¼±¸¹Û²ì±ä»»¾ØÕóÁË¡£ÔÙÒ»´ÎÇë×¢Ò⣺¶¨ÒåÈÎÒ»±ä»»µÄ˳Ðò²»Êǹؼü¡£ÎÞÂÛÈçºÎ£¬Direct3D ²ÉÓÃÒÔÏÂ˳Ðò½«ÕâЩ¾ØÕó×÷ÓÃÓÚ³¡¾°£º(1) ÊÀ½ç£¬(2) ¹Û²ì£¬(3) Ó³Éä¡£

¶¨Òå¹Û²ì±ä»»¾ØÕóÇë²Î¿´ µÚ¶þ²½£º¶¨Òå¹Û²ì±ä»»¾ØÕó

µÚ¶þ²½£º¶¨Òå¹Û²ì±ä»»¾ØÕó£¨View Transformation Matrix£©

¹Û²ì±ä»»¾ØÕó¶¨ÒåÁ˹۲ìµÄλÖúÍÐýת½Ç¶È¡£´Ë¹Û²ì¾ØÕó¾ÍÏ൱ÓÚ³¡¾°µÄÉãÓ°»ú¡£

ÒÔÏ´úÂëƬ¶Î´´½¨ÁËÒ»¸ö¹Û²ì±ä»»¾ØÕó²¢½«ÆäÉèÖÃΪ Microsoft Direct3D É豸µÄµ±Ç°¹Û²ì¾ØÕó¡£

D3DXMATRIX matView;

D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0.0f, 3.0f,-5.0f ),

&D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),

&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );

g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

µÚÒ»²½ÊÇͨ¹ýµ÷Óà D3DXMatrixLookAtLH ¶¨Òå¹Û²ì¾ØÕó¡£µÚÒ»¸ö²ÎÊýÊÇÒ»¸öÖ¸Ïò D3DXMATRIX ½á¹¹µÄÖ¸Õ룬ÓÃÀ´½ÓÊܲÙ×÷½á¹û¡£µÚ¶þ¡¢Èý¡¢Ëĸö²ÎÊý¶¨ÒåÁ˹۲ìµã¡¢×¢Êӵ㡢ÒÔ¼°·½Ïò¡°ÉÏ¡±¡£Õâ¶ùÉèÖù۲ìµãΪÑØ Z-Öá ·´·½Ïò 5 µ¥Î»ÔÙÍùÉÏ 3 µ¥Î»£¬×¢ÊÓµãΪԭµã£¬ÒÔ¼°×÷Ϊ¡°ÉÏ¡±µÄ·½ÏòΪ Y-Öá¡£

ÏÂÒ»²½Êǵ÷Óà IDirect3DDevice8::SetTransform ¸ø Direct3D É豸ÉèÖù۲ì¾ØÕó¡£SetTransform ½ÓÊܵĵÚÒ»¸ö²ÎÊý֪ͨ Direct3D ÄÄÒ»¸ö±ä»»½«Òª±»ÉèÖ᣸ÃÀý³ÌʹÓà D3DTS_VIEW ±ê¼ÇÖ¸¶¨Îª¹Û²ì¾ØÕó¡£µÚ¶þ¸ö²ÎÊýÊÇÒ»¸öÖ¸Ïò¾ØÕóµÄÖ¸Õ룬Ëü±»ÉèΪµ±Ç°µÄ±ä»»¡£

¹ØÓÚ¹Û²ì¾ØÕóµÄ¸ü¶àÐÅÏ¢£¬¼û£ºSDK: View Transformation

¶¨ÒåÁ˳¡¾°µÄÊÀ½ç±ä»»ºó£¬Äã¿ÉÒÔ¿ªÊ¼×¼±¸Ó³Éä±ä»»¾ØÕóÁË¡£ÔÙÒ»´ÎÌáÐÑ£¬¶¨Òåÿһ±ä»»µÄ˳Ðò²»ÊǹؼüÐԵġ£ÎÞÂÛÈçºÎ£¬Direct3D ×ÜÊDzÉÓÃÒÔÏÂ˳Ðò½«¾ØÕóÓ¦ÓÃÓÚ³¡¾°£º(1) ÊÀ½ç£¬(2) ¹Û²ì£¬(3) Ó³Éä¡£

¶¨ÒåÓ³Éä±ä»»¾ØÕóµÄ¹¤×÷±»ÃèÊöÔÚ µÚÈý²½£º¶¨ÒåÓ³Éä±ä»»¾ØÕó

µÚÈý²½£º¶¨ÒåÓ³Éä±ä»»¾ØÕó£¨Projection Transformation Matrix£©

Ó³Éä±ä»»¾ØÕó¶¨ÒåÁ˽« 3-D ¹Û²ì¿Õ¼äת»»Îª 2-D ÊÓ¿Ú¿Õ¼äµÄ¼¸ºÎѧ·½·¨¡£

ÒÔÏ´úÂëƬ¶Î´´½¨Ó³Éä±ä»»¾ØÕó²¢½«ÆäÉèΪ Microsoft Direct3D É豸µÄµ±Ç°Ó³Éä±ä»»¡£

D3DXMATRIX matProj;

D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );

g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

µÚÒ»²½Êǵ÷Óà D3DXMatrixPerspectiveFovLH ÉèÖÃÓ³Éä¾ØÕ󡣺¯ÊýµÚÒ»¸ö²ÎÊýÊÇÒ»¸öÖ¸Ïò D3DXMATRIX µÄ½á¹¹£¬ÓÃÓÚ½ÓÊܲÙ×÷µÄ½á¹û¡£µÚ¶þ¸ö²ÎÊý¶¨ÒåÊÓ³¡£¬Ëü˵Ã÷ÎïÌåÈçºÎËæמàÀë¶øËõС¡£Ò»¸öµäÐ͵ÄÊÓ³¡ÊÇ 1/4 ¦Ð£¬¾ÍÏñÕâ¸öÀý×ÓʹÓõÄÒ»Ñù¡£µÚÈý¸ö²ÎÊý¶¨ÒåÁËÆÁÄ»×ݺá±È¡£±¾Ê¾Àý²ÉÓõäÐ͵Ä×ݺá±È 1¡£µÚËĺ͵ÚÎå¸ö²ÎÊý¶¨Òå×î½üºÍ×îÔ¶¼ôÇÐƽÃæ¡£ÕâÊÇÓÃÓÚÈ·¶¨Î»ÓÚºÎÖÖ¾àÀëÖ®ÍâµÄ¼¸ºÎÎïÌåÎÞÐèÔÙ»æÖÆ¡£±¾ Matrices ʾÀýÉèÖÃËüµÄ×î½ü¼ôÇÐƽÃæΪ 1£¬×îÔ¶¼ôÇÐƽÃæΪ 100¡£

ÏÂÒ»²½Êǵ÷Óà IDirect3DDevice8::SetTransfrom ¶Ô Direct3D Ó¦Óñ任¡£SetTransfrom ½ÓÊܵĵÚÒ»¸ö²ÎÊý֪ͨ Direct3D ºÎÖֱ任±»ÉèÖᣱ¾Àý³ÌʹÓà D3DTS_PROJECTION ±êÖ¾Ö¸¶¨Ó³Éä±ä»»½«±»ÉèÖᣵڶþ¸ö²ÎÊýÊÇÒ»¸öÖ¸Ïò¾ØÕóµÄÖ¸Õ룬Ëü½«±»ÉèÖÃΪµ±Ç°µÄ±ä»»¡£

¹ØÓÚÓ³Éä±ä»»µÄ¸ü¶àÐÅÏ¢£¬²Î¼û£º¡°Ó³Éä±ä»»¡±

±¾Ö¸ÄÏÒѾ­ÌáʾÄãÈçºÎʹÓþØÕó¡£Ö¸ÄÏËÄ£º´´½¨ºÍʹÓùâÔ´ ½«½ÒʾÈçºÎÔÚÄãµÄ³¡¾°ÖÐÌí¼Ó¹âÔ´ÒÔÔö¼ÓÕæʵÐÔ¡£

Ö¸ÄÏËÄ£º´´½¨ºÍʹÓùâÔ´

Microsoft Direc3D ¹âÕÕϵͳ¸ø 3-D ÎïÌåÌṩ¸ü¶àµÄÕæʵÐÔ¡£µ±Ê¹ÓÃËüʱ£¬Ã¿¸ö³¡¾°Öеļ¸ºÎ¶ÔÏ󽫱»ÕÕÁÁ£¬»ùÓÚËüÃǵÄλÖúÍʹÓõĹâÔ´ÀàÐÍ¡£Õâ¸öÖ¸ÄϵÄÀý³Ì½«½éÉܹØÓÚ¹âÕպͲÄÖʵÄÖ÷Ìâ¡£

±¾Ö¸ÄÏ°üº¬ÒÔϲ½ÖèÓÃÓÚ´´½¨²ÄÖÊÓë¹âÕÕ£º

¡¤µÚÒ»²½£º´´Ê¼»¯³¡¾°¼¸ºÎ

¡¤µÚ¶þ²½£ºÉèÖòÄÖÃÓë¹âÕÕ

×¢Ò⣺Lights ʾÀý³ÌÐòµÄ·¾¶Îª£º

(SDK root)\Samples\Multimedia\Direct3D\Tutorials\Tut04_Lights.

×¢Ò⣺Lights Àý³ÌÖеĴúÂëºÍ Matrices Àý³ÌµÄ´úÂ뼸ºõÍêÈ«Ò»Ñù¡£¡°´´½¨ºÍʹÓùâÔ´¡±Ö¸ÄϽö½ö¹Ø×¢ÓÚÓйش´½¨ºÍʹÓùâÕյĶÀÌØ´úÂ룬¶ø²¢²»Öظ´ÓйØÉèÖà Direct3D£¬´¦Àí Microsoft Windows ÏûÏ¢£¬»æÖÆ£¬»òÕßÇåÀíµÄÄÚÈÝ¡£¹ØÓÚÕâЩÈÎÎñµÄÆäËûÐÅÏ¢£¬¼û£ºÖ¸ÄÏÒ»£º´´½¨É豸¡£

±¾Ö¸ÄÏʹÓÃ×Ô¶¨Ò嶥µãºÍ¶¥µã»º³åÇø³ÊµÝ¼¸ºÎÐÎÌå¡£¹ØÓÚÑ¡ÔñÒ»¸ö×Ô¶¨Ò嶥µã¸ñʽ²¢Ö´Ðж¥µã»º³åµÄ¸ü¶àÐÅÏ¢£¬¼û£ºÖ¸Ä϶þ£ºÑÝʾ¶¥µã¡£

±¾Ö¸ÄϲÉÓþØÕó±ä»»¼¸ºÎ¶ÔÏó¡£¹ØÓÚ¾ØÕóºÍ±ä»»µÄ¸ü¶àÐÅÏ¢£¬²Î¼û£ºÖ¸ÄÏÈý£ºÊ¹ÓþØÕó¡£

µÚÒ»²½£º´´Ê¼»¯³¡¾°¼¸ºÎ

ʹÓùâÕÕµÄÒ»¸öÇ°ÌáÊÇÿ¸ö±íÃ涼Ӧ¸ÃÓз¨ÏòÁ¿¡£Îª´Ë£¬Lights Àý³ÌʹÓÃÒ»¸öÉÔ΢²»Í¬µÄ×Ô¶¨Ò嶥µã¸ñʽ£¬ÐµÄ×Ô¶¨Ò嶥µã¸ñʽ¾ßÓÐÒ»¸ö 3-D λÖÃ×ø±êºÍÒ»¸ö±íÃæ·¨ÏòÁ¿¡£Õâ¸ö±íÃæ·¨ÏòÁ¿±»ÓÃÓÚ Microsoft Direct3D ¹âÕÕ¼ÆËãµÄºËÐÄ¡£

struct CUSTOMVERTEX

{

D3DXVECTOR3 position; // The 3-D position for the vertex.

D3DXVECTOR3 normal; // The surface normal for the vertex.

};

// Custom FVF.

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL)

ÏÖÔÚÊʵ±µÄʸÁ¿¸ñʽ¶¨ÒåºÃÁË£¬Lights Àý³Ìµ÷Óà InitGeometry()£¬Ò»¸ö³ÌÐò×Ô¶¨ÒåµÄº¯ÊýÒÔ´´½¨Ò»¸öÔ²ÖùÌå¡£×î³õµÄ²½ÖèÊÇ´´½¨Ò»¸ö¶¥µã»º³åÇø²¢ÓÃËü±£´æÕâ¸öÔ²ÖùÌåµÄ¸÷µã£¬ÈçÒÔÏÂÀý´úÂëËùʾ£º

// Create the vertex buffer.

if( FAILED( g_pd3dDevice->CreateVertexBuffer( 50*2*sizeof(CUSTOMVERTEX),

0 /* Usage */, D3DFVF_CUSTOMVERTEX,

D3DPOOL_DEFAULT, &g_pVB ) ) )

return E_FAIL;

ÏÂÒ»²½ÊÇʹÓÃÔ²ÖùÌåµÄ¶¥µãÌî³ä¶¥µã»º³åÇø¡£×¢ÒâÏÂÃæµÄʾÀý´úÂ룬ÿ¸öµã¶¼±»¶¨ÒåÁËÒ»¸öλÖúÍÒ»¸ö·¨ÏòÁ¿¡£

for( DWORD i=0; i<50; i++ )

{

FLOAT theta = (2*D3DX_PI*i)/(50-1);

pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );

pVertices[2*i+0].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );

pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );

pVertices[2*i+1].normal = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );

}

ÔÚÇ°ÊöÀý³ÌʹÓÃÔ²ÖùÌ嶥µãÌî³äÁ˶¥µã»º³åÇøÖ®ºó£¬Õâ¸ö¶¥µã»º³åÇøÒѾ­×¼±¸ºÃÓÃÓڳʵÝÁË¡£µ«ÊÇÊ×ÏÈ£¬Õâ¸ö³¡¾°µÄ²ÄÖÊÓë¹âÕÕ±ØÐëÔÚ»æÖÆÔ²ÖùÌå֮ǰ±»ÉèÖá£ÕâЩÃèÊöÔÚ µÚ¶þ²½£ºÉèÖòÄÖÊÓë¹âÕÕ¡£

µÚ¶þ²½£ºÉèÖòÄÖÊÓë¹âÕÕ

ΪÁËÔÚ Microsoft Direct3D ÖÐʹÓùâÕÕ£¬Äã±ØÐë´´½¨Ò»¸ö»ò¶à¸ö¹âÔ´¡£ÎªÁËÈ·¶¨Ò»¸ö¼¸ºÎÎïÌå·ÅÉäºÎÖÖÑÕÉ«µÄ¹âÏߣ¬²ÄÖʱØÐë±»´´½¨ÓÚ»æÖƼ¸ºÎ¶ÔÏó¡£ÔÚ»æÖÆÕâ¸ö³¡¾°Ö®Ç°£¬Lights Àý³Ìµ÷Óà SetupLights£¬Ò»¸ö³ÌÐò×Ô¶¨Ò庯ÊýÀ´ÉèÖòÄÖʺÍÒ»¸ö·½ÏòÐÔ¹âÔ´¡£

´´½¨Ò»ÖÖ²ÄÖÊ

²ÄÖʱ»¶¨ÒåΪµ±Ò»Êø¹âÕÕµ½¼¸ºÎÎïÌå±íÃæºó£¬·´Éä³öµÄÑÕÉ«¡£ÒÔÏ´úÂëƬ¶ÎʹÓà D3DMATERIAL8 ½á¹¹À´´´½¨Ò»¸ö»ÆÉ«µÄ²ÄÖÊ¡£

D3DMATERIAL8 mtrl;

ZeroMemory( &mtrl, sizeof(D3DMATERIAL8) );

mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;

mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;

mtrl.Diffuse.b = mtrl.Ambient.b = 0.0f;

mtrl.Diffuse.a = mtrl.Ambient.a = 1.0f;

g_pd3dDevice->SetMaterial( &mtrl );

Õâ¸ö²ÄÖʵÄÂþÉä¹âÑÕÉ«Óë»·¾³¹âÑÕÉ«¶¼±»ÉèΪ»ÆÉ«¡£¶Ô IDirect3DDevice8::SetMaterial º¯ÊýµÄµ÷Óý«Ó¦Óô˲ÄÖʵ½ÓÃÓÚ»æÖƳ¡¾°µÄ Microsoft Direct3D É豸¡£SetMaterial() ½ÓÊܵÄΨһ²ÎÊýÊÇÉèÖòÄÖʵÄÖ¸Õë¡£ÔÚÕâ¸öµ÷ÓÃÍê³ÉÒÔºó£¬Ã¿¸öÎï¼þ¶¼½«Ê¹ÓÃÕâ¸ö²ÄÖÊ»æÖÆÖ±µ½ÁíÒ»´Î¶Ô SetMaterial µÄµ÷ÓÃÖ¸¶¨ÁËÒ»¸ö²»Í¬µÄ²ÄÖÊΪֹ¡£

ÏÖÔÚ²ÄÖÊÒѾ­±»Ó¦Óõ½³¡¾°£¬ÏÂÒ»¸ö²½ÖèÊÇ´´½¨¹âÔ´¡£

´´½¨Ò»¸ö¹âÔ´

Microsoft Direct3D ÀïÓÐÈýÖÖ¿ÉÓõĹâÔ´£ºµã¹âÔ´£¬·½ÏòÐιâÔ´£¬Óë¾Û¹âµÆ¹âÔ´¡£±¾Ê¾Àý´úÂë´´½¨Ò»¸ö·½ÏòÐιâÔ´£¬ËüÏòÒ»¸ö·½Ïò·¢¹â£¬²¢ÇÒ²»Í£µÄ±ä»»·¢¹âµÄ·½Ïò¡£

ÏÂÁдúÂëƬ¶ÎʹÓà D3DLIGHT8 ½á¹¹´´½¨Ò»¸ö·½ÏòÐÔ¹âÔ´¡£

D3DXVECTOR3 vecDir;

D3DLIGHT8 light;

ZeroMemory( &light, sizeof(D3DLIGHT8) );

light.Type = D3DLIGHT_DIRECTIONAL;

ÏÂÁдúÂëƬÉèÖùâÔ´µÄÂþÉä¹âΪ°×É«¡£

light.Diffuse.r = 1.0f;

light.Diffuse.g = 1.0f;

light.Diffuse.b = 1.0f;

ÒÔÏ´úÂëƬÔÚÒ»¸ö»·ÄÚÐýת¹âÔ´µÄ·½Ïò¡£

vecDir = D3DXVECTOR3(cosf(timeGetTime()/360.0f),

0.0f,

sinf(timeGetTime()/360.0f) );

D3DXVec3Normalize( (D3DXVECTOR3*)&light.Direction, &vecDir );

¶Ô D3DXVec3Normalize º¯ÊýµÄµ÷Óý«¹éÒ»»¯·½ÏòʸÁ¿²¢³õʼ»¯¹âÔ´µÄ·½Ïò¡£

¿ÉÒÔÉèÖÃÒ»¸ö·¶Î§¸æËß Direct3D ´Ë¹âÔ´ÄÜÓ°Ïì¶àÔ¶µÄ¾àÀë¡£Õâ¸ö³ÉÔ±²ÎÊý¶Ô·½ÏòÐÔ¹âÔ´ÎÞЧ¡£ÒÔÏ´úÂëƬָ¶¨´Ë¹âÔ´µÄ·¶Î§Îª 1000 µ¥Î»¡£

light.Range = 1000.0f;

ÏÂÃæµÄ´úÂëƬ½«Õâ¸ö¹âÔ´·ÖÅäµ½µ±Ç°µÄ Direct3D É豸£¬Í¨¹ýµ÷Óà IDirect3DDevice8::SetLight¡£

g_pd3dDevice->SetLight( 0, &light );

SetLight ½ÓÊܵĵÚÒ»¸ö²ÎÊýÊǴ˹âÔ´±»·ÖÅäµÄË÷ÒýºÅ¡£×¢ÒâÈç¹ûÔÚ´ËË÷ÒýÒÑ´æÔÚÒ»¸ö¹âÔ´£¬Ëü½«±»Ð¹âÔ´¸²¸Ç¡£µÚ¶þ¸ö²ÎÊýÊÇÒ»¸öÖ¸Ïòж¨Òå¹âÔ´Êý¾Ý½á¹¹µÄÖ¸Õë¡£±¾ Lights Àý³ÌÉèÖÃÕâ¸ö¹âԴλÓÚ 0 ºÅË÷Òý¡£

ÏÂÁдúÂëƬ¼¤»îÕâ¸ö¹âÔ´£¬Í¨¹ýµ÷Óà IDirect3DDevice8::LightEnable¡£

g_pd3dDevice->LightEnable( 0, TRUE);

LightEnable ½ÓÊܵĵÚÒ»¸ö²ÎÊýÊǼ¤»î¹âÔ´µÄË÷Òý¡£µÚ¶þ¸ö²ÎÊýÊÇÒ»¸ö²¼¶ûÁ¿Í¨Öª´Ë¹âÔ´ÊÇ¿ª (TRUE) »¹ÊÇ±Õ (FALSE)¡£ÔÚÉÏÃæµÄÀý³ÌÖУ¬Ë÷Òý 0 ÉϵĹâÔ´±»´ò¿ª¡£

ÒÔÏ´úÂëƬ֪ͨ Direct3D ³ÊµÝ´Ë¹âÔ´£¬Í¨¹ýµ÷Óà IDirect3DDevice8::SetRenderState¡£

g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

SetRenderState ½ÓÊܵÄÍ·Á½¸ö²ÎÊýÊÇÄÄÒ»¸öÉ豸״̬±äÁ¿±»¸ÄдÒÔ¼°Ð´ÈëºÎÖÖÖµ¡£±¾Àý³ÌÉèÖà D3DRS_LIGHTING É豸±äÁ¿Îª TRUE£¬Õ⽫ʹÉ豸Äܹ»ÑÝʾ¹âÕÕЧ¹û¡£

±¾Àý³ÌµÄ×îºóÒ»²½ÊÇͨ¹ýÔÙÒ»´Îµ÷Óà SetRenderState ´ò¿ª»·¾³ÕÕÃ÷¹â¡£

g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x00202020 );

µ±Ç°´úÂë¶ÎÉèÖà D3DRS_AMBIENT É豸±äÁ¿ÎªÒ»ÖÖdz»ÒÉ« (0x00202020)¡£»·¾³ÕÕÃ÷½«Ê¹ÓÃËù¸øµÄÑÕÉ«ÕÕÁÁËùÓеÄÎïÌå¡£

¹ØÓÚÕÕÃ÷¼°²ÄÖʵĸü¶àÐÅÏ¢£¬²Î¼û SDK: Lights and Materials¡£

±¾Àý³ÌÏòÄã˵Ã÷ÁËÈçºÎʹÓÃÕÕÃ÷Óë²ÄÖÊ¡£Ö¸ÄÏÎ壺ʹÓÃÎÆÀíÓ³Éä ½«ÏòÄã˵Ã÷ÈçºÎ½«ÎÆÀíÌí¼Óµ½ÎïÌå±íÃæÉÏ¡£

Ö¸ÄÏÎ壺ʹÓÃÎÆÀíÓ³Éä

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00379