作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如果我想创建一个 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/
我是一名优秀的程序员,十分优秀!