2

如果我想创建一个 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 设备数组?

4

1 回答 1

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);
}
于 2012-11-01T17:03:20.620 回答