锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Describes the presentation parameters. In fact, D3DFMT_UNKNOWN can be specified for the BackBufferFormat while in windowed mode. This tells the runtime to use the current display-mode format and eliminates the need to call IDirect3DDevice9::GetDisplayMode. For windowed applications, the back buffer format no longer needs to match the display-mode format because color conversion can now be done by the hardware (if the hardware supports color conversion). The set of possible back buffer formats is constrained, but the runtime will allow any valid back buffer format to be presented to any desktop format. (There is the additional requirement that the device be operable in the desktop mode; devices typically do not operate in 8 bits per pixel modes.) Full-screen applications cannot do color conversion. The method fails if one back buffer cannot be created. The value of BackBufferCount influences what set of swap effects are allowed. Specifically, any D3DSWAPEFFECT_COPY swap effect requires that there be exactly one back buffer. D3DSWAPEFFECT_COPY requires that BackBufferCount be set to 1. D3DSWAPEFFECT_DISCARD will be enforced in the debug runtime by filling any buffer with noise after it is presented. Differences between Direct3D9 and Direct3D9Ex In Direct3D9Ex, D3DSWAPEFFECT_FLIPEX is added to designate when an application is adopting flip mode. That is, whan an application's frame is passed in window's mode (instead of copied) to the Desktop Window Manager(DWM) for composition. Flip mode provides more efficient memory bandwidth and enables an application to take advantage of full-screen-present statistics. It does not change full screen behavior. Flip mode behavior is available beginning with Windows 7. For a full-screen application, this is a handle to the top window (which is the focus window). For applications that use multiple full-screen devices (such as a multimonitor system), exactly one device can use the focus window as the device window. All other devices must have unique device windows. Note that no attempt is made by the runtime to reflect user changes in window size. The back buffer is not implicitly reset when this window is reset. However, the IDirect3DDevice9::Present method does automatically track window position changes. If EnableAutoDepthStencil is TRUE, then AutoDepthStencilFormat must be a valid depth-stencil format. Header: Declared in D3D9Types.h.
鐜板湪鍏抽敭鐨勯棶棰樺氨鍦ㄤ簬,璧勬簮閿佸畾鐨勬搷浣滈熷害鎬繪槸闈炲父涔嬫參.褰撶劧,浣犱細璺熸垜鎻? OpenGL浼間箮鑳藉蹇嵎鍦板畬鎴愯繖欏逛換鍔?浣嗘槸,鍦―irect3D涓?璧勬簮閿佸畾鎿嶄綔紜疄鏄緢鎱㈢殑.榪欓噷闈竴涓富瑕佺殑鍘熷洜鏄?API,椹卞姩,浠ュ強紜歡瑕佸鐞嗕竴浜涗笉鍙洖閬跨殑鍚庡彴鎿嶄綔.閭e氨鏄疓PU涓嶤PU鏄茍琛岃繍琛岀殑,鑻ヤ笉鍔犱換浣曟帾鏂?灝嗗紩璧風被浼煎綰跨▼紼嬪簭鍚屾鏃剁殑绔炴佹潯浠剁殑闂. 濡傛灉浣犺瘯鍥懼幓淇敼鐨勮祫婧愭鍚屾椂琚竴涓綅浜嶨PU澶勭悊搴忓垪涓殑鎸囦護浣跨敤,閭d箞鏁翠釜娓叉煋嫻佺▼灝變細鍥犱負浣犵殑璧勬簮閿佸畾鑰屽仠欏挎垨寮哄埗鍒鋒柊(stalls and flushes).鍋滈】(stall)浼氫竴鐩存寔緇埌浣犲畬鎴愪簡瀵硅祫婧愮殑淇敼騫惰皟鐢║nlock().鑰屽己鍒跺埛鏂?flush)鍒欎細瑕佹眰GPU鍦ㄤ綘寰楀埌榪欎釜璧勬簮鐨勮闂潈涔嬪墠瀹屾垚鐩墠鎵鏈夌殑浠誨姟. 濡備綍鍘昏В鍐寵繖涓棶棰橈紵涓嬮潰鐨勫弬鑰冭祫鏂欎腑鏈変竴浜涜В鍐蟲柟妗堬紝鎴戞病鏈夌粡榪囪鐪熸祴璇曪紝鎴戣瘯浜嗗叾涓竴涓狦etRenderTargetData 榪欐牱鐨勪竴縐嶆柟娉?錛屾劅瑙変笉澶ソ鐢紝why璇風湅Reference3 涓嬮潰緇欏嚭鎴戠殑瑙e喅鏂規 鍙傝冭祫鏂欙細Reference1.http://www.cnblogs.com/mixiyou/archive/2010/02/25/1673060.html Reference 2.http://www.cnblogs.com/mixiyou/archive/2010/02/25/1673425.html Reference 3.http://blog.csdn.net/Nightmare/article/details/1707362 Reference 4.http://www.cnblogs.com/lancidie/archive/2011/3/14.html
綆浠?/strong>
褰撴垜浠垱寤烘父鎴忓拰浠跨湡妯℃嫙鏃訛紝鏈夋椂鎴戜滑鏈夊繀瑕佽褰曟覆鏌撶殑鍐呭銆傚湪鏌愪簺鎯呭喌涓嬫覆鏌撹繃浜庡鏉傚拰鑰楁椂錛岃繖鏄笉鍙伩鍏嶇殑銆?br /> 鍦―irectX涓紝搴撳嚱鏁癉3DXSaveSurfaceToFile()淇濆瓨琛ㄩ潰涓轟竴寮犲浘鐗囨枃浠躲傚OpenGL錛屾垜浠敤glReadPixels()鏉ヨ娓叉煋鐨勫浘鍍忓儚绱犵劧鍚庢墜鍔ㄧ殑淇濆瓨瀹冧滑涓轟竴寮犲浘鐗囨枃浠躲傜劧鑰岃繖浜涜〃闈㈠彧鏄拡瀵瑰崟甯ц褰曠殑錛屽璁板綍涓孌佃繛緇撫娌℃湁綆鍗曠殑鏂規硶瀛樺湪銆傛崲鍙ヨ瘽璇?娌℃湁搴撳嚱鏁版潵璁板綍鎴戜滑鐨勫畬鏁村瓨鍦ㄦ覆鏌撳姩鐢繪晥鏋溿?br /> 鍦ㄨ繖鏂歸潰,鏈枃鎻愬嚭浜嗗嚑綾?榪欐湁鍔╀簬鍒涢犵數褰盌irectX鐨勬柟娉曞拰鍔ㄧ敾銆傜敤綾籆DxToMovie鍜?CGLToMovie鐢靛獎鍙互閫夋嫨鎬у湴鎴栬繛緇殑浠嶥irectX鍜孫penGL娓叉煋甯ф潵鍒涘緩銆備竴鑸潵璇?涓涓吀鍨嬬殑鐢靛獎鍒涗綔榪囩▼娑夊強澶嶆潅鐨勪換鍔?渚嬪璇誨浘鐨勫唴瀹?閫夋嫨甯ч熺巼璁劇疆,緙栬В鐮佸櫒鐨勮緗?鍒濆鍖栧獟浣撴祦,鍐欏獟浣撴祦絳夛紙璇︾粏璁ㄨ鍏充簬濡備綍鍒涘緩浣嶅浘鍥懼儚搴忓垪鐨勭數褰?璇峰弬鑰冭繖綃囨枃绔?a >Create Movie from HBitmap錛夈傜被CDxToMovie鍜孋GLToMovie榪欓噷浠嬬粛鐨勬娊璞″嚭鎵鏈変笉蹇呰鐨勫鏉傛у拰鏄撲簬浣跨敤鐨勭晫闈?鎻愪緵綆鍗曟柟娉曡В閲婂涓?br />浠嶥irectX娓叉煋搴忓垪璁板綍涓涓數褰?br /> 綾籆DxToMovie鍙互璁板綍DirectX娓叉煋搴忓垪鎴愮數褰辨枃浠躲傝綾葷敤鍒癉irectX 9.0鎺ュ彛渚嬪LPDIRECT3DSURFACE9錛屽洜姝や綘搴旇鐢―irectX 9.0 SDK 鎴栬呭叾浠栫殑鍏煎鐨勫湴鏂逛嬌鐢ㄨ繖涓被 銆?br /> 寮濮嬩粠鏈枃涓殑DirectX浠g爜鎷瘋礉鏂囦歡DxToMovie.h錛孯enderTarget.h錛孉viFile.h鍜孉viFile.cpp鍒頒綘鐨勫伐紼嬬洰褰曚笅鐒跺悗娣誨姞浠栦滑鍒頒綘鐨勫伐紼嬩腑錛岀劧鍚庢坊鍔爒fw.lib錛屼竴鏃︽坊鍔犲埌浣犵殑宸ョ▼涓紝浣犲彲浠ラ氳繃#include "DxToMovie.h"璁塊棶銆侰DxToMovie鏋勯犲嚱鏁版帴鍙椾笉鍚岀殑鍙傛暟濡傝緭鍑虹數褰辨枃浠跺悕,鐢靛獎甯х殑瀹藉害鍜岄珮搴︾殑瑕佹眰,姣忓儚绱犳瘮鐗規暟絳?#8230;濡備笅鎵紺?
CDxToMovie(LPCTSTR lpszOutputMovieFileName = _T("Output.avi"),
int nFrameWidth = GetSystemMetrics(SM_CXSCREEN), /*Movie Frame Width*/
int nFrameHeight = GetSystemMetrics(SM_CYSCREEN), /*Movie Frame Height*/
int nBitsPerPixel = 32, /*Bits per Pixel*/
DWORD dwCodec = mmioFOURCC('M','P','G','4'), /*Video Codec for Compression*/
DWORD dwFrameRate = 1) /*Frame Rate (FPS) setting for the Movie*/
CDxToMovie g_MovieRecorder("Output.Avi", 320, 240);
class CDxToMovie
{
HRESULT OnCreateDevice(LPDIRECT3DDEVICE9 pd3dDevice);
HRESULT OnDestroyDevice(LPDIRECT3DDEVICE9 pd3dDevice);
HRESULT OnLostDevice();
HRESULT OnResetDevice(LPDIRECT3DDEVICE9 pd3dDevice,
const D3DSURFACE_DESC* pBackBufferSurfaceDesc);
};IDirect3DDevice9::EndScene()涔嬮棿銆傚涓嬫墍紺?
鍦ㄤ笂闈㈢殑浠g爜孌典腑錛?nbsp;
g_pd3dDevice->BeginScene();
// Capture the Rendering onto CDxToMovie's Render Target
g_MovieRecorder.StartRecordingMovie(g_pd3dDevice);
// Render as usual
..
g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,200),1,0);
g_pd3dDevice->SetStreamSource(0,g_pVB,0,sizeof(CUSTOMVERTEX));
g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
g_MovieRecorder.PauseRecordingMovie(g_pd3dDevice);
// Copy the CDxToMovie's Render Target content back onto BackBuffer's Surface
g_pd3dDevice->StretchRect(g_MovieRecorder.RecordingSurface(),
NULL,pBackSurface,
0,D3DTEXF_NONE);
g_pd3dDevice->EndScene();g_MovieRecorder.StartRecordingMovie(g_pd3dDevice)灝嗘墍鏈夐殢鍚庣殑娓叉煋鍦–DxToMovie鐨勫唴閮ㄦ覆鏌撶洰鏍囩洿鍒?font face="Courier New">g_MovieRecorder.PauseRecordingMovie(g_pd3dDevice)琚皟鐢ㄣ傛墍鏈夌殑娓叉煋宸ヤ綔鍦–DxToMovie鐨勫唴閮ㄦ覆鏌撶洰鏍囦笂鍋氾紝浣犵殑紼嬪簭back surface灝嗘病鏈変換浣曟湁鏁堢殑鍐呭鏄劇ず鍦ㄤ綘鐨勫簲鐢ㄧ▼搴忕獥鍙c傝繖涓嶈绱?濡傛灉浣犵殑鐢寵涓嶅彧鏄垱浣滆繖閮ㄧ數褰辨病鏈変換浣曞姩鐢葷洿鎺ュ憟鐜板湪灞忓箷涓娿傜劧鑰?濡傛灉浣犺褰曠數褰變粠涓涓簰鍔ㄦ父鎴忎細璇濅笂,瀹冧細鍙樺潖灞忓箷涓嶆洿鏂板埌鏈鏂扮殑娓叉煋鐨勫唴瀹?鍥犱負閫氳繃閲嶆柊娓叉煋鐩爣錛孋DxToMovie鍐呭琚伔浜?銆備負浜嗛伩鍏嶅畠,浣犲彲浠ラ夋嫨鎬у湴澶嶅埗鍥濩DxToMovie鍐呴儴鐨勬覆鏌撶洰鏍囩殑鍐呭鍒頒綘鐨勫簲鐢ㄧ▼搴忕殑back surface 浣跨敤鏂規硶IDirect3DDevice9:StretchRect(),鍏舵鏄父瑙佺殑g_pd3dDevice - > EndScene()鍜実_pd3dDevice - >Present()鐨勮姹備細鏇存柊鍐呭鐨勫憟鐜板湪灞忓箷涓婅儗緙撳啿鍖?浣垮睆騫曚笂鏇存柊銆?br />濡傛灉浣犳兂閬垮厤涓浜涘撫琚夋嫨鎬ц褰曞湪榪欓儴鐢靛獎,鍙槸涓嶈鍙玤_MovieRecorder.StartRecordingMovie鍜実_MovieRecorder.PauseRecordingMovie()(鐩稿簲鐨?g_pd3dDevice - > StretchRect())瀵歸偅浜涘撫,騫朵細鐩存帴娓叉煋鍔ㄧ敾鍦ㄥ睆騫曚笂(娌℃湁琚噸瀹氬悜鍒癈DxToMovie鍐呴儴鐨勬覆鏌撶洰鏍?銆?br />婕旂ず浠g爜鎻愪緵榪欎釜欏圭洰鎻愪緵浜嗕竴涓畝鍗曠殑搴旂敤紼嬪簭,浣垮緱DirectX灞忓箷涓婄殑涓涓笁瑙掑艦鐨勫姩浣?榧犳爣縐誨姩紿楁埛涓?榪欏皢simulatenously琚覆鏌撴垚鐢靛獎鏂囦歡鍜岃褰?鍚嶅彨output.avi)銆傝窇婕旂ず鐨勫彲鎵ц紼嬪簭,紜繚浣犳湁MPG4緙栬В鐮佸櫒鐨勮綆楁満涓婂畨瑁?鐩綍鏈夊啓鏉冮檺鍘誨垱寤鴻緭鍑虹數褰辨枃浠躲傝鎯呰璁劇疆瑙g爜鍣ㄥ拰騫寵 ,璇峰弬鑰冭繖綃囨枃绔?a >Create Movie from HBitmap
Recording a Movie from OpenGL Rendered Sequence
鍏堟殏鏃朵笉緲昏瘧浜嗭紝浠ュ悗鍐嶇炕銆?br />
娉細絎竴嬈$炕璇戯紝姘村鉤姣旇緝宸紝榪樻湜鍚勪綅鐪嬪瑙佽皡銆?br />Reference錛?nbsp;Recording DirectX and OpenGL Rendered Animations
]]>
鍒涘緩Direct3D璁懼瀵硅薄鏃訛紝闇瑕佸厛鍒涘緩Direct3D瀵硅薄錛岀劧鍚庡啀璋冪敤Direct3D瀵硅薄鐨勬帴鍙e嚱鏁癐Direct3D9錛氾細CreateDevice鍒涘緩Direct3D璁懼瀵硅薄銆傞氳繃鍚屼竴涓狣irect3D瀵硅薄鍒涘緩鐨勬墍鏈塂irect3D璁懼瀵硅薄鍏變韓鐩稿悓鐨勭墿鐞嗚祫婧愶紙鏄懼崱錛夈傚洜涓哄叡浜悓涓紜歡錛屾墍浠ュ鏋滈氳繃涓涓狣irect3D瀵硅薄鍒涘緩澶氫釜Direct3D娓叉煋璁懼瀵硅薄浼氭槑鏄鵑檷浣庣郴緇熸ц兘銆?br /> 鍦ㄥ垱寤篋irect3D璁懼瀵硅薄涔嬪墠錛岃繕闇瑕佸厛鍒濆鍖朌3DPRESENT_PARAMENTERS緇撴瀯錛岃緇撴瀯鐢ㄤ簬鍒涘緩Direct3D璁懼瀵硅薄銆傛緇撴瀯灝嗕細褰卞搷Direct3D璁懼鐨勬樉紺烘柟娉曘?br />
D3DPRESENT_PARAMETERS
typedef struct D3DPRESENT_PARAMETERS {
UINT BackBufferWidth, BackBufferHeight;
D3DFORMAT BackBufferFormat;
UINT BackBufferCount;
D3DMULTISAMPLE_TYPE MultiSampleType;
DWORD MultiSampleQuality;
D3DSWAPEFFECT SwapEffect;
HWND hDeviceWindow;
BOOL Windowed;
BOOL EnableAutoDepthStencil;
D3DFORMAT AutoDepthStencilFormat;
DWORD Flags;
UINT FullScreen_RefreshRateInHz;
UINT PresentationInterval;
} D3DPRESENT_PARAMETERS, *LPD3DPRESENT_PARAMETERS;
Members
Requirements
鍑犱釜閲嶈鐨勫弬鏁板姞浠ヨВ閲婅鏄庝竴涓嬶紝鍏朵腑BackBufferWidth鍜孊ackBufferHeight鎸囧畾鍚庡彴緙撳瓨鍖虹殑瀹介珮錛堜互鍍忕礌涓哄崟浣嶏級銆傚鏋滃浘褰互紿楀彛鏂瑰紡鏄劇ず騫朵笖璇ユ垚鍛樺彉閲忚璁劇疆涓?錛屽垯緋葷粺鑷姩浣跨敤鏄劇ず紿楀彛瀹㈡埛鍖虹殑瀹介珮浣滀負鍚庡彴緙撳啿鍖虹殑瀹介珮銆侭ackBufferCount鎸囧畾鍚庡彴緙撳啿鍖虹殑鏁伴噺銆傝鍊煎彲浠ヤ負0銆?銆?銆?錛屽叾涓?鍜?鏃墮兘琛ㄧず鍒涘緩涓涓悗鍙扮紦鍐插尯銆傞氬父浣跨敤涓涓悗鍙扮紦鍐插尯鍜屼竴涓富緙撳瓨錛屼富緙撳瓨灝嗗叾鏄劇ず鍦ㄥ睆騫曚笂銆?br />
]]>
Direct3D 11 Runtime
To obtain the Direct3D 11 runtime, please install the release version of Windows 7 or Windows Server 2008 R2. Windows Vista users can follow the procedure described in KB 971644 (or KB 971512 for corporate network users).
http://support.microsoft.com/kb/971644
鍏蜂綋濡備綍鍘誨疄鐜頒竴涓狣irectX2D Application 鍙傝DirectX 2010.6 鐗堟湰涓璖DK鏂囨。——Windows DirectX Graphics Documention——Direct2D
Direct2D鍏ラ棬錛?a >http://blog.pfan.cn/lym51/52200.html
浣跨敤Direct2D緇樺浘http://msdn.microsoft.com/zh-cn/magazine/ee413543.aspx
]]>
BOOL CD3DCameraViewWnd::GetImageInfo(DWORD* pPixelBuffer, int& width,int& height)
{
BOOL result = FALSE;
IDirect3DSurface9 *_surfaceback = NULL;
if (FAILED(m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &_surfaceback)))
{
result = FALSE;
}
D3DSURFACE_DESC surfaceDesc;
if (!FAILED(_surfaceback->GetDesc(&surfaceDesc)))
{
width = surfaceDesc.Width;
height = surfaceDesc.Height;
}
D3DLOCKED_RECT lockedRect;
HRESULT hr = _surfaceback->LockRect( &lockedRect,0, 0); /* pointer to receive locked data鎸囧悜鐢寵鍒扮殑鍐呭瓨鍖哄煙*/ /* lock entire surface*/// no lock flags specified
if (!FAILED(hr))
{
pPixelBuffer = (DWORD*)lockedRect.pBits;
result = TRUE;
}
_surfaceback->UnlockRect();
_surfaceback->Release();
return result;
}BOOL CD3DCameraViewWnd::GetImageInfo(DWORD* pPixelBuffer, int& width,int& height)
{
BOOL result = FALSE;
IDirect3DSurface9 *_surfaceback = NULL;
if (FAILED(m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &_surfaceback)))
{
result = FALSE;
}
D3DSURFACE_DESC surfaceDesc;
if (!FAILED(_surfaceback->GetDesc(&surfaceDesc)))
{
width = surfaceDesc.Width;
height = surfaceDesc.Height;
} LPDIREC3DSURFACE9 surf; if(FAILED(m_pDevice->CreateOffscreenPlainSurface(width, height,D3DFMT_A8R8G8B8,D3DPOOL_SYSTEMMEM, &surf,NULL))) { result = FALSE; } D3DXLoadSurfaceFromSurface(surf, NULL,NULL,_surfaceback,NULL,NULL,D3DX_FILTER_NONE,0);
D3DLOCKED_RECT lockedRect;
HRESULT hr = surf->LockRect( &lockedRect,0, 0); /* pointer to receive locked data鎸囧悜鐢寵鍒扮殑鍐呭瓨鍖哄煙*/ /* lock entire surface*/// no lock flags specified
if (!FAILED(hr))
{
pPixelBuffer = (DWORD*)lockedRect.pBits;
result = TRUE;
}
surf->UnlockRect(); surf->Release();
_surfaceback->Release();
return result;
}
]]>