• <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>

            天行健 君子當自強而不息

            DXUT框架剖析(2)

            DXUT框架用來幫助程序員花更少的時間來解決下列問題:創建窗口、創建Direct3D設備、進行消息循環和處理設備事件。在DXUT框架基礎上編寫代碼,可以快速高效地進行Direct3D程序設計,大多數Direct3D SDK示例程序使用了DXUT框架。

            下面的代碼是AppFrame示例程序的WinMain函數:

            INT WINAPI wWinMain( HINSTANCE, HINSTANCE, LPWSTR, int )
            {
            // Enable run-time memory check for debug builds.
            #if defined(DEBUG) | defined(_DEBUG)
            _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
            #endif
                // Set the callback functions
            DXUTSetCallbackD3D9DeviceAcceptable(IsD3D9DeviceAcceptable);
            DXUTSetCallbackD3D9DeviceCreated(OnD3D9CreateDevice);
            DXUTSetCallbackD3D9DeviceReset(OnD3D9ResetDevice);
            DXUTSetCallbackD3D9FrameRender(OnD3D9FrameRender);
            DXUTSetCallbackD3D9DeviceLost(OnD3D9LostDevice);
            DXUTSetCallbackD3D9DeviceDestroyed(OnD3D9DestroyDevice);
            DXUTSetCallbackDeviceChanging(ModifyDeviceSettings);
            DXUTSetCallbackMsgProc(MsgProc);
            DXUTSetCallbackFrameMove(OnFrameMove);
                // TODO: Perform any application-level initialization here
                // Initialize DXUT and create the desired Win32 window and Direct3D device for the application
                DXUTInit( true, true ); // Parse the command line and show msgboxes
            DXUTSetHotkeyHandling( true, true, true ); // handle the default hotkeys
            DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen
            DXUTCreateWindow( L"AppFrame Sample" );
            DXUTCreateDevice( true, 640, 480 );
                // Start the render loop
            DXUTMainLoop();
                // TODO: Perform any application-level cleanup here
                return DXUTGetExitCode();
            }

            在上面的代碼中,DXUT框架做了大部分的工作。它創建了一個窗口和一個Direct3D設備,處理消息循環、并當事件發生時(例如重新設置設備或渲染一幀)調用應用程序提供的回調函數。 DXUT框架是模塊化的,所以應用程序可以使用DXUT框架的所有函數或其中的一部分。

            下面這組代碼時一組注冊函數的調用:

                // Set the callback functions
                DXUTSetCallbackD3D9DeviceAcceptable(IsD3D9DeviceAcceptable);
                DXUTSetCallbackD3D9DeviceCreated(OnD3D9CreateDevice);
                DXUTSetCallbackD3D9DeviceReset(OnD3D9ResetDevice);
                DXUTSetCallbackD3D9FrameRender(OnD3D9FrameRender);
                DXUTSetCallbackD3D9DeviceLost(OnD3D9LostDevice);
                DXUTSetCallbackD3D9DeviceDestroyed(OnD3D9DestroyDevice);
                DXUTSetCallbackDeviceChanging(ModifyDeviceSettings);
                DXUTSetCallbackMsgProc(MsgProc);
                DXUTSetCallbackFrameMove(OnFrameMove);

            以函數DXUTSetCallbackD3D9DeviceCreated為例,它的聲明如下:

            Sets the Direct3D 9 device created callback function.

            VOID DXUTSetCallbackD3D9DeviceCreated(
            LPDXUTCALLBACKD3D9DEVICECREATED pCallback,
            void* pUserContext
            );

            Parameters

            pCallback
            [in] Pointer to a LPDXUTCALLBACKD3D9DEVICECREATED callback function. If the callback function is supplied, it will be called after the Direct3D 9 device has been created. Device creation will happen during application initialization and if the device is changed. If NULL, DXUT will not notify the application about device creation.
            pUserContext
            [in] Pointer to a user-defined value which is passed to the callback function. Typically used by an application to pass a pointer to a data structure that provides context information for the callback function. The default value is NULL

            Return Values

            No return value.

            Remarks

            This function only needs to be called if the application supports rendering with Direct3D 9 device.

            The LPDXUTCALLBACKD3D9DEVICECREATED callback function is the appropriate location for the application to create Direct3D 9 device resources that will live through a device reset such as D3DPOOL_MANAGED or D3DPOOL_SYSTEMMEM memory and that aren't tied to the back buffer size. Resources created in the LPDXUTCALLBACKD3D9DEVICECREATED callback function should be released in the LPDXUTCALLBACKD3D9DEVICEDESTROYED callback function.

            LPDXUTCALLBACKD3D9DEVICECREATED

            Application-defined resource creation callback function, called by DXUT after the Direct3D 9 device is created. Passes a pointer to the newly created Direct3D 9 device.

            HRESULT LPDXUTCALLBACKD3D9DEVICECREATED(
            IDirect3DDevice9 * pd3dDevice,
            CONST D3DSURFACE_DESC * pBackBufferSurfaceDesc,
            void* pUserContext
            );

            Parameters

            pd3dDevice
            [out] Pointer to the newly created Direct3D 9 device.
            pBackBufferSurfaceDesc
            [out] Pointer to the back buffer surface description
            pUserContext
            [in] Pointer to a user-defined value which is passed to the callback function. Typically used by an application to pass a pointer to a data structure that provides context information for the callback function. The default value is NULL

            Return Values

            In general, if no error occurs, program the function to return S_OK. Program the function to return an HRESULT failure code if the function fails. If DXUT receives a failure HRESULT code, it shuts down the application.

            Remarks

            The LPDXUTCALLBACKD3D9DEVICECREATED callback function is the appropriate location for the application to create Direct3D 9 device resources that will live through a device reset such as D3DPOOL_MANAGED or D3DPOOL_SYSTEMMEM memory and that aren't tied to the back buffer size. Resources created in the LPDXUTCALLBACKD3D9DEVICECREATED callback function should be released in the LPDXUTCALLBACKD3D9DEVICEDESTROYED callback function.

            該注冊函數的作用在于通知應用程序,在應用程序的初始化期間或當設備改變時,如果需要創建D3DPOOL_MANAGED類型的資源,就會自動調用函數OnD3D9CreateDevice()進行創建。而程序員需要做的就是編寫OnD3D9CreateDevice()函數,告訴應用程序創建哪些資源以及如何創建。其他注冊函數的作用同樣是通知應用程序,使應用程序在特定時機調用注冊函數指定的具體回調函數。程序員的核心工作就是實現這些具體的回調函數,事實上,這種構架正是DXUT框架的核心,也可以把它看成是區別于Direct3D API程序的地方。

            DXUT框架提供了下列服務,幫助程序員創建一個應用程序:

            (1)簡化窗口和設備的創建。

            (2)聲明設備事件(創建、重置、丟失、銷毀)和窗口事件(消息、鍵盤、鼠標)。

            (3)在窗口模式和全屏模式間切換,在硬件抽象層設備和參考設備間切換。

            (4)高分辨率計時器。

            (5)為自動測試提供命令行支持。

            (6)通過對話框或API選擇設備。

            (7)紋理GUI控件組,包括IME-enable文本框。

            (8)附加雜類,例如簡單的攝像機類。

            為使用方便,DXUT框架支持Direct3D設備和窗口一一對應(一個設備只能對應一個窗口)。對于需要同時使用多個設備或顯示多個Direct3D窗口的高級應用程序,該框架不支持。不過,大多數應用程序只使用一個窗口和一個Direct3D設備,所以大部分應用程序都能使用該框架。


            posted on 2008-05-15 12:12 lovedday 閱讀(2308) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            狠狠干狠狠久久| 精品久久久久香蕉网| 久久久WWW成人免费毛片| 亚洲国产日韩欧美久久| 亚洲精品无码久久久影院相关影片 | 伊人久久大香线蕉综合Av | 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 色综合久久久久综合99| 人妻无码αv中文字幕久久琪琪布| 精品久久久久久无码国产| 亚洲综合日韩久久成人AV| 99久久99久久精品国产片| 亚洲精品高清国产一线久久| 久久成人精品| 久久久久亚洲av无码专区喷水| 久久九色综合九色99伊人| 久久国产精品99国产精| 一本一本久久a久久精品综合麻豆| 久久婷婷国产麻豆91天堂| 久久亚洲私人国产精品vA | 日本精品久久久久中文字幕| 色婷婷综合久久久久中文| 97视频久久久| 99久久香蕉国产线看观香| 亚洲色欲久久久久综合网| 亚洲精品NV久久久久久久久久| 成人午夜精品久久久久久久小说| 久久精品www人人爽人人| 久久亚洲熟女cc98cm| 国产香蕉久久精品综合网| 亚洲AV伊人久久青青草原| 亚洲欧美成人久久综合中文网| 久久久久九九精品影院| 91精品免费久久久久久久久| 婷婷综合久久中文字幕| 久久这里只有精品久久| 国产午夜精品久久久久九九电影| 91久久精品视频| 日韩欧美亚洲国产精品字幕久久久| 久久夜色精品国产亚洲av| 国产精品中文久久久久久久|