C++ 如何在C+中创建IDirect3DSurface9(D3D曲面)曲面数组+;?
如果我想创建一个D3D曲面,我会像下面这样做。类似地,如果我想创建一个类型为dDirect3dSure99的D3D表面数组,我在C++中如何做?C++ 如何在C+中创建IDirect3DSurface9(D3D曲面)曲面数组+;?,c++,arrays,visual-c++,directx,direct3d,C++,Arrays,Visual C++,Directx,Direct3d,如果我想创建一个D3D曲面,我会像下面这样做。类似地,如果我想创建一个类型为dDirect3dSure99的D3D表面数组,我在C++中如何做? IDirect3DSurface9** ppdxsurface = NULL; IDirect3DDevice9 * pdxDevice = getdevice(); // getdevice is a custom function which gives me //the d3d device. pdxDevice->CreateOffs
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设备数组?<>强> < p> <代码> ppdxSurbs/Cuff>没有正确声明,需要提供指向<强>指针对象< /强>的指针,而不只是指针指针。它应该是
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);
}
非常感谢。将“IDirect3DSurface9*pdxsurface[maxSurfaces]={0};”为10个元素的数组创建内存,因为我们刚刚实例化了1个元素{0}。我们不应该做{0,0<代码>{}只是初始化列表。我们用
0
初始化了第一个元素,以显示数组已初始化。其余元素将自动默认初始化(归零)。实际上,它相当于您的命题:{0,0,0,0,0,0,0,0}
,但要短得多。::当我这样做时{0}甚至{0,0,…0},我得到了构建错误,预期的常量表达式&无法分配大小为0的数组。@codeLover看起来您在语法方面遗漏了一些东西。再检查一遍。已证明可以使用VS2003进行编译+
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);
}