如果我想创建一个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);
QUERY ::如何在C ++中创建D3D设备数组?
答案 0 :(得分:5)
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);
要创建曲面数组,只需在循环中调用它:
// 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);
}
如果您更喜欢动态数组,请使用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);
}