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

            麒麟子

            ~~

            導(dǎo)航

            <2011年5月>
            24252627282930
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            統(tǒng)計(jì)

            常用鏈接

            留言簿(12)

            隨筆分類

            隨筆檔案

            Friends

            WebSites

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            [轉(zhuǎn)]關(guān)于Direct3D多窗口編程的一篇翻譯


            In DirectX 8, support for rendering to multiple windows is provided through the creation of additional swap chains. However, there are currently no examples of this in the SDK, and the documentation is a bit vague. This article is provided to fill the gaps, and will explain the steps you need to take to write an application that will render multiple views in separate windows.


            在DX8中,對多窗口的支持是通過創(chuàng)建更多的Swap Chains來提供的。SDK中沒有相關(guān)的例子而且文檔也只是泛泛而談。這篇文章就是為了解決這個(gè)問題,它將向您展示應(yīng)當(dāng)如何一步步地實(shí)現(xiàn)在多個(gè)分離窗口中渲染多個(gè)視圖。

             

             

            Step 1 - Setting Up The Parent Frame


            第一步:設(shè)置父框架窗口

             

             

            In an application with multiple views, we start with a top level frame that will contain child windows in its client area to display various views. Once the parent frame parent frame has been created, we create our Direct3D device interface, specifying windowed mode and setting the top level window handle as the focus window:


            在多視圖的應(yīng)用程序中,我們需要從最高層次的框架——這個(gè)框架將包含所有在他用戶區(qū)之內(nèi)的子視圖窗口——開始我們的旅程。當(dāng)父框架創(chuàng)建的時(shí)候,我們需要創(chuàng)建Direct3D Device接口,為其指定使用窗口模式,而且設(shè)置這最高層次的窗口句柄作為“焦點(diǎn)窗口”的句柄:

             

             

            g_pD3D=Direct3DCreate8(D3D_SDK_VERSION);


            if (!g_pD3D) return -1;


            D3DPRESENT_PARAMETERS d3dpp;


            ZeroMemory( &d3dpp, sizeof(d3dpp) );


            d3dpp.Windowed = TRUE;


            d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;


            // Use the current display mode. 使用當(dāng)前的顯示模式


            D3DDISPLAYMODE mode;

            if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT , &mode))) {


                SAFE_RELEASE(g_pD3D);


                return -1;


            }


            d3dpp.BackBufferFormat = mode.Format;


            d3dpp.BackBufferWidth = mode.Width;


            d3dpp.BackBufferHeight = mode.Height;


            d3dpp.EnableAutoDepthStencil=TRUE;


            d3dpp.AutoDepthStencilFormat = D3DFMT_D16;


            // m_hWnd is handle to top level window    m_hWnd是最高層窗口的句柄


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


                                              D3DCREATE_SOFTWARE_VERTEXPROCESSING,


                                              &d3dpp, &g_pd3dDevice) ) ) {


                SAFE_RELEASE(g_pD3D);


                return -1;


            }

             

             


            Note that for simplicity the above code does not test depth format, instead choosing a fixed format. Your application should determine a compatible depth format for the format of the rendering target.


            注意上面代碼處于簡單考慮并沒有去測試深度緩存的格式(?depth format),而只是選擇了一個(gè)確定的格式(D3DFMT_D16)。您的程序應(yīng)該為需要渲染的Render Target選擇一個(gè)可接受的深度緩存格式。

             

             

            The device has a frame buffer, which the child views will be rendered into, as well as a depth buffer which will be shared among the views. The frame buffer and depth buffer are sized to the full screen resolution, to allow for the fact that the window may later be resized. Otherwise, window size changes would require resetting the device and re-creating the swap chains.


            Device都需要有幀緩存,這樣子視圖才能進(jìn)行渲染,同時(shí),深度緩沖也應(yīng)當(dāng)被不同的視圖進(jìn)行共享。幀緩存和深度緩存都被設(shè)置為全屏幕大小,以考慮到可能窗口會被改變大小的情況。如果不的話,窗口改變大小的時(shí)候,就需要Reset Device和重新創(chuàng)建Swap Chain。

             

             

            Step 2 - Setting Up View Windows


            第二步:設(shè)置子視圖窗口

             

             

            Now we are ready to create our view windows, and associate them with swap chains that can be rendered to the device. Once the windows have been created, the following code generates a swap chain for the child window:


            現(xiàn)在我們可以準(zhǔn)備創(chuàng)建我們的子窗口也就是視圖窗口,并把它們與交換鏈關(guān)聯(lián)以使得他們可以被渲染到Device上。當(dāng)窗口創(chuàng)建后,下面的代碼將為子窗口創(chuàng)建一個(gè)交換鏈:

             

             

            D3DPRESENT_PARAMETERS d3dpp;


            ZeroMemory( &d3dpp, sizeof(d3dpp) );


            d3dpp.Windowed = TRUE;


            d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;


            // Use the current display mode. 使用當(dāng)前的顯示模式


            D3DDISPLAYMODE mode;


            g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT , &mode);


            d3dpp.BackBufferFormat = mode.Format;


            // m_hWnd contains child window handle m_hWnd儲存子窗口的句柄


            d3dpp.hDeviceWindow=m_hWnd;


            // m_pSwapChain is IDirect3DSwapChain *   m_pSwapChain是一個(gè)IDirect3DSwapChain*對象


            g_pd3dDevice->CreateAdditionalSwapChain(&d3dpp, &m_pSwapChain);

             

             


            After executing this code, the m_pSwapChain variable will contain a pointer to an IDirect3DSwapChain interface, which contains a frame buffer corresponding to the client area of the child window. This process is performed for each view window, so that that there is a swap chain for each view window.


            經(jīng)過這些代碼之后,m_pSwapChain變量就儲存了IDirect3DSwapChain接口的指針,這個(gè)接口將儲存子窗口視圖區(qū)所對應(yīng)的幀緩沖。

             

             

            Step 3 - Rendering a View

            第三步:渲染視圖

             

             

            Prior to rendering each view, we must direct the device to render to the appropriate frame buffer, using the SetRenderTarget() method. We pass the back buffer from the window's swap chain, while using the depth buffer that was originally created with the device:


            在渲染每個(gè)視圖窗口之前,我們必須使得Device來渲染對應(yīng)的幀緩沖,這我們就需要用到SetRenderTarget方法。我們向其中傳入子窗口SwapChain交換鏈的后備緩沖BackBuffer,以及使用最開始跟著Device一起創(chuàng)建的深度緩沖。

             

             

            LPDIRECT3DSURFACE8 pBack=NULL,pStencil=NULL;


            m_pSwapChain->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&pBack);


            g_pd3dDevice->GetDepthStencilSurface(&pStencil);


            g_pd3dDevice->SetRenderTarget(pBack,pStencil);


            pBack->Release();


            pStencil->Release();

             

             


            Note that we release the stencil and backbuffer pointers after we use them, because the GetBackBuffer() and GetDepthStencilSurface() functions call AddRef() on these interfaces to increment their reference counters. Failing to release them would lead to a memory leak.


            注意我們必須Release掉Stencil和BackBuffer的指針,因?yàn)镚etBackBuffer和GetDepthStencilSurface這兩個(gè)函數(shù)都會調(diào)用COM的AddRef方法,來增加相應(yīng)COM接口的引用計(jì)數(shù),因此如果不刪除它們,將會導(dǎo)致內(nèi)存泄露。

             

             

            We are now ready to render the view. Rendering is performed within a scene in the normal manner, except that we call Present() on the swap chain interface rather than the device interface:


            我們現(xiàn)在已經(jīng)做好準(zhǔn)備渲染視圖窗口了。渲染的方法看起來和我們平常用的方法差不多,只是有一點(diǎn):我們現(xiàn)在需要調(diào)用Swap Chain的接口,而不是Device的接口。

             

             

            g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0x00000000,1.0,0);


            if (SUCCEEDED(g_pd3dDevice->BeginScene())) {


              


                // rendering code goes here 渲染代碼寫在這里

             

             


                g_pd3dDevice->EndScene();


            }


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

             

             


            Step 4 - Handling Resize of Child Views


            第四步,子窗口的Resize問題

             

             

            DirectX will automatically deal with changes in the child view by using a stretch blit to present the swap chain if the dimensions have client area is not the same size as the swap chain's frame buffer. However, this may not be desirable, as it will cause aliasing if the client area is increased in size.


            如果窗口的視圖區(qū)大小和SwapChain的大小不一,那么DirectX將通過Stretch Blit來自動處理圖像的伸縮變化。盡管這可能并不令人期待,因?yàn)檫@在視圖區(qū)變大的時(shí)候?qū)?dǎo)致圖像的模糊。

             

            posted on 2009-08-10 17:32 麒麟子 閱讀(2434) 評論(4)  編輯 收藏 引用 所屬分類: DirectX

            評論

            # re: [轉(zhuǎn)]關(guān)于Direct3D多窗口編程的一篇翻譯 2009-08-10 22:23 kuafoo

            始終沒找到你發(fā)的那個(gè)兩個(gè)小游戲源碼  回復(fù)  更多評論   

            # re: [轉(zhuǎn)]關(guān)于Direct3D多窗口編程的一篇翻譯 2009-08-11 00:01 Leaf

            @kuafoo
            額,我不曉得怎么放耶!!!  回復(fù)  更多評論   

            # re: [轉(zhuǎn)]關(guān)于Direct3D多窗口編程的一篇翻譯 2009-08-12 12:05 戴爾電腦

            不錯(cuò)啊  回復(fù)  更多評論   

            # re: [轉(zhuǎn)]關(guān)于Direct3D多窗口編程的一篇翻譯 2009-09-11 16:14 wu

            <如果窗口的視圖區(qū)大小和SwapChain的大小不一,那么DirectX將通過Stretch Blit來自動處理圖像的伸縮變化。盡管這可能并不令人期待,因?yàn)檫@在視圖區(qū)變大的時(shí)候?qū)?dǎo)致圖像的模糊。> 你說的這個(gè)問題 要怎么才能解決?
              回復(fù)  更多評論   

            99久久夜色精品国产网站| 国产精品九九久久免费视频 | 狠狠色丁香久久婷婷综合五月| 性高湖久久久久久久久| 国产精品免费福利久久| 久久久精品免费国产四虎| 久久精品久久久久观看99水蜜桃| 色综合久久无码五十路人妻| 国内精品伊人久久久久| 中文国产成人精品久久不卡| 久久精品国产69国产精品亚洲 | 久久精品视频一| 国产精品成人99久久久久91gav| 亚洲国产成人精品无码久久久久久综合| 精品久久久无码人妻中文字幕豆芽| 久久精品国产99国产精偷| 国产高清美女一级a毛片久久w| 久久久久久久久久久久久久| 国内精品久久久久久麻豆 | 欧美综合天天夜夜久久| 2019久久久高清456| 一本色道久久88综合日韩精品| 久久91精品国产91久久小草| 一本一本久久a久久综合精品蜜桃 一本一道久久综合狠狠老 | 中文成人无码精品久久久不卡| 99久久国产主播综合精品| 色综合久久久久网| 久久综合九色综合网站| 精品精品国产自在久久高清| 精品伊人久久大线蕉色首页| 噜噜噜色噜噜噜久久| 国内精品久久久久久中文字幕 | 青草影院天堂男人久久| 狠狠久久亚洲欧美专区| 精品久久久久久中文字幕| 久久精品99久久香蕉国产色戒 | 精品综合久久久久久88小说| 一级做a爱片久久毛片| 亚洲国产精品婷婷久久| 999久久久国产精品| 久久福利片|