cod*_*ver 2 c++ arrays directx direct3d visual-c++
如果我想创建一个D3D表面,我会像下面这样做.同样,如果我想创建一个IDirect3DSurface9类型的D3D表面数组*我该怎么做C++?
IDirect3DSurface9** ppdxsurface = NULL;
IDirect3DDevice9 * pdxDevice = getdevice(); // getdevice is a custom function which gives me //the d3d device.
pdxDevice->CreateOffscreenPlainSurface(720,480,
D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
pdxsurface,
NULL);
Run Code Online (Sandbox Code Playgroud)
QUERY ::如何在C++中创建D3D设备数组?
ppdxsurface
未正确声明,您需要提供指针对象的指针,而不仅仅是指向指针的指针.应该是IDirect3DSurface9*
,而不是IDirect3DSurface9**
:
IDirect3DSurface9* pdxsurface = NULL;
IDirect3DDevice9* pdxDevice = getdevice();
pdxDevice->CreateOffscreenPlainSurface(720, 480,
D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
&pdxsurface, // Pass pointer to pointer
NULL);
// Usage:
HDC hDC = NULL;
pdxsurface->GetDC(hDC);
Run Code Online (Sandbox Code Playgroud)
要创建曲面数组,只需在循环中调用它:
// Define array of 10 surfaces
const int maxSurfaces = 10;
IDirect3DSurface9* pdxsurface[maxSurfaces] = { 0 };
for(int i = 0; i < maxSurfaces; ++i)
{
pdxDevice->CreateOffscreenPlainSurface(720, 480,
D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
&pdxsurface[i],
NULL);
}
Run Code Online (Sandbox Code Playgroud)
或者std::vector
如果您更喜欢使用动态数组:
std::vector<IDirect3DSurface9*> surfVec;
for(int i = 0; i < maxSurfaces; ++i)
{
IDirect3DSurface9* pdxsurface = NULL;
pdxDevice->CreateOffscreenPlainSurface(720, 480,
D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
&pdxsurface,
NULL);
surfVec.push_back(pdxsurface);
}
Run Code Online (Sandbox Code Playgroud)