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

            天行健 君子當自強而不息

            Direct3D程序設計基礎(3)

            渲染圖形

            使用Direct3D繪制三維圖形和使用GDI繪制二維圖形的方法非常類似,Direct3D程序中的Direct3D設備對象相當于GDI程序中的hdc(設備描述表),使用 GDI繪制圖形前,通常需要先利用hdc進行相關設置,然后通過hdc進行繪圖。同樣在Direct3D程序中通常先通過Direct3D設備接口進行相關的渲染設備設置,然后再渲染圖形。而且所有的渲染圖形操作必須在函數(shù)BeginScene()和EndScene()之間進行。

            void render()
            {
            g_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_X#2d32aa, 1.0f, 0);
            	g_device->BeginScene();
            	// render game scene here 
            	g_device->EndScene();
            	g_device->Present(NULL, NULL, NULL, NULL);
            }

            IDirect3DDevice9::Clear()函數(shù)的作用是清空一個或多個表面的內(nèi)容。Direct3D在繪制圖形前,需要使用該函數(shù)清空視口(viewport)的顏色緩沖區(qū)、深度緩沖區(qū)或者模板緩沖區(qū)。

            Clears one or more surfaces such as a render target, multiple render targets, a stencil buffer, and a depth buffer.

            HRESULT Clear(
            DWORD Count,
            CONST D3DRECT * pRects,
            DWORD Flags,
            D3DCOLOR Color,
            float Z,
            DWORD Stencil
            );

            Parameters

            Count
            [in] Number of rectangles in the array at pRects. Must be set to 0 if pRects is NULL. May not be 0 if pRects is a valid pointer.
            pRects
            [in] Pointer to an array of D3DRECT structures that describe the rectangles to clear. Set a rectangle to the dimensions of the rendering target to clear the entire surface. Each rectangle uses screen coordinates that correspond to points on the render target. Coordinates are clipped to the bounds of the viewport rectangle. To indicate that the entire viewport rectangle is to be cleared, set this parameter to NULL and Count to 0.
            Flags
            [in] Combination of one or more D3DCLEAR flags that specify the surface(s) that will be cleared.
            Color
            [in] Clear a render target to this ARGB color.
            Z
            [in] Clear the depth buffer to this new z value which ranges from 0 to 1. See remarks.
            Stencil
            [in] Clear the stencil buffer to this new value which ranges from 0 to 2n - 1 (n is the bit depth of the stencil buffer). See remarks.

            Return Values

            If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be: D3DERR_INVALIDCALL.

            Remarks

            Use this method to clear a surface including: a render target, all render targets in an MRT, a stencil buffer, or a depth buffer. Flags determines how many surfaces are cleared. Use pRects to clear a subset of a surface defined by an array of rectangles.

            IDirect3DDevice9::Clear will fail if you:

            • Try to clear either the depth buffer or the stencil buffer of a render target that does not have an attached depth buffer.
            • Try to clear the stencil buffer when the depth buffer does not contain stencil data.

            大多數(shù)三維圖形程序擁有2個或者更多顏色緩沖區(qū)。用于當前屏幕刷新的顏色緩沖區(qū)稱為前臺緩沖區(qū),而將用于圖形繪制的其他顏色緩沖區(qū)稱為后臺緩沖區(qū)。同時擁有前臺緩沖區(qū)和后臺緩沖區(qū)的圖形程序可以同時進行圖形繪制和屏幕刷新工作,系統(tǒng)的運行性能優(yōu)于僅有單個顏色緩沖區(qū)的圖形程序。在Direct3D程序中最常見的情況是有一個前臺緩沖區(qū)和一個后臺緩沖區(qū)。

            在繪制圖形開始之前,必須先調(diào)用函數(shù)IDirect3DDevice9::BeginScene()函數(shù),通知Direct3D設備開始繪制圖形(又稱渲染),否則Direct3D程序就會出錯返回;渲染程序完成后,也必須調(diào)用函數(shù)IDirect3DDevice9::EndScene()通知Direct3D設備結(jié)束渲染。而且這兩個函數(shù)必須成對出現(xiàn),不允許嵌套和交錯的情況發(fā)生。任何Direct3D渲染函數(shù)都必須在函數(shù)BeginScene()和函數(shù)EndScene()的中間出現(xiàn)。

            Direct3D在后臺緩沖區(qū)進行圖形繪制操作,當所有的圖形繪制操作結(jié)束之后,調(diào)用函數(shù)IDirect3DDevice9::Present()將在后臺緩沖區(qū)繪制的內(nèi)容提交到前臺顯示,這樣繪制的圖形就顯示在屏幕上了。

            Presents the contents of the next buffer in the sequence of back buffers owned by the device.

            HRESULT Present(
            CONST RECT * pSourceRect,
            CONST RECT * pDestRect,
            HWND hDestWindowOverride,
            CONST RGNDATA * pDirtyRegion
            );

            Parameters

            pSourceRect
            [in] Pointer to a value that must be NULL unless the swap chain was created with D3DSWAPEFFECT_COPY. pSourceRect is a pointer to a RECT structure containing the source rectangle. If NULL, the entire source surface is presented. If the rectangle exceeds the source surface, the rectangle is clipped to the source surface.
            pDestRect
            [in] Pointer to a value that must be NULL unless the swap chain was created with D3DSWAPEFFECT_COPY. pDestRect is a pointer to a RECT structure containing the destination rectangle, in window client coordinates. If NULL, the entire client area is filled. If the rectangle exceeds the destination client area, the rectangle is clipped to the destination client area.
            hDestWindowOverride
            [in] Pointer to a destination window whose client area is taken as the target for this presentation. If this value is NULL, then the hWndDeviceWindow member of D3DPRESENT_PARAMETERS is taken.
            pDirtyRegion
            [in] Value must be NULL unless the swap chain was created with D3DSWAPEFFECT_COPY. For more information about swap chains, see Flipping Surfaces (Direct3D 9) and D3DSWAPEFFECT. If this value is non-NULL, the contained region is expressed in back buffer coordinates. The rectangles within the region are the minimal set of pixels that need to be updated. This method takes these rectangles into account when optimizing the presentation by copying only the pixels within the region, or some suitably expanded set of rectangles. This is an aid to optimization only, and the application should not rely on the region being copied exactly. The implementation can choose to copy the whole source rectangle.

            Return Values

            Possible return values include: D3D_OK or D3DERR_DEVICEREMOVED (see D3DERR).

            Remarks

            If necessary, a stretch operation is applied to transfer the pixels within the source rectangle to the destination rectangle in the client area of the target window.

            IDirect3DDevice9::Present will fail, returning D3DERR_INVALIDCALL, if called between BeginScene and EndScene pairs unless the render target is not the current render target (such as the back buffer you get from creating an additional swap chain). This is a new behavior for Direct3D 9.


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

            公告

            導航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            久久精品一区二区国产| 久久综合九色综合网站| 久久精品亚洲中文字幕无码麻豆| 亚洲午夜久久久久久久久久| 国产成人精品免费久久久久| 日韩AV毛片精品久久久| 国产V综合V亚洲欧美久久| 国产成人久久777777| 狠狠色丁香久久婷婷综合图片| 无码精品久久一区二区三区| 久久久一本精品99久久精品88| 国产成人久久精品麻豆一区| 久久99精品国产麻豆宅宅| 欧美成a人片免费看久久| 欧美亚洲国产精品久久蜜芽| 亚洲精品成人网久久久久久| 国产综合免费精品久久久| 日本久久久精品中文字幕| 狠狠色丁香久久婷婷综合蜜芽五月| 99久久人妻无码精品系列蜜桃 | 青青草原综合久久大伊人精品| 思思久久99热只有频精品66| 久久97久久97精品免视看| 久久久免费精品re6| 国产69精品久久久久9999APGF| 久久露脸国产精品| 久久国产精品国产自线拍免费| 久久精品国产乱子伦| 亚洲а∨天堂久久精品9966| 国内精品伊人久久久久影院对白| 老色鬼久久亚洲AV综合| 久久精品国产99国产精偷| 色婷婷综合久久久久中文 | 色综合合久久天天综合绕视看| 一本一道久久综合狠狠老| 久久久高清免费视频| 免费一级欧美大片久久网| 久久婷婷五月综合成人D啪| 欧美粉嫩小泬久久久久久久| 亚洲国产成人久久综合碰| 午夜精品久久影院蜜桃|