gpt4 book ai didi

c++ - 如何在 C++ 中创建 IDirect3DSurface9(D3D 表面)表面数组?

转载 作者:搜寻专家 更新时间:2023-10-31 00:41:27 26 4
gpt4 key购买 nike

如果我想创建一个 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);

问题::如何在 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);

要创建曲面数组,只需在循环中调用它:

// 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);
}

关于c++ - 如何在 C++ 中创建 IDirect3DSurface9(D3D 表面)表面数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13180830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com