Directx中D3DPRESENT_PARAMETERS未声明的问题
在SDK中最简单的列子中,我自己定义了DX的类如下
文件名MyDirectx.h
#include<windows.h>
class MyDirectx
{
public:
MyDirectx(void);
~MyDirectx(void);
void init(HWND hWnd); 只有一个初始化就让我很崩溃了
//void Render();
//void Cleanup();
private:
LPDIRECT3D9 g_pD3D;
LPDIRECT3DDEVICE9 g_pd3dDevice;
};
MyDirectx::MyDirectx(void)
{
LPDIRECT3D9g_pD3D = NULL;
LPDIRECT3DDEVICE9g_pd3dDevice = NULL;
}
MyDirectx::~MyDirectx(void)
{
}
void MyDirectx::init(HWND hWnd)
{
// Create the D3D object, which is needed to create the D3DDevice.
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
// return E_FAIL;
// Set up the structure used to create the D3DDevice. Most parameters are
// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
// window, and then set the SwapEffect to "discard", which is the most
// efficient method of presenting the back buffer to the display. And
// we request a back buffer format that matches the current desktop display
// format.
D3DPRESENT_PARAMETERS AAA; 出问题的地方
ZeroMemory( &AAA, sizeof( AAA ) );
AAA.Windowed = TRUE;
AAA.SwapEffect = D3DSWAPEFFECT_DISCARD;
AAA.BackBufferFormat = D3DFMT_UNKNOWN;
// Create the Direct3D device. Here we are using the default adapter (most
// systems only have one, unless they have multiple graphics hardware cards
// installed) and requesting the HAL (which is saying we want the hardware
// device rather than a software one). Software vertex processing is
// specified since we know it will work on all cards. On cards that support
// hardware vertex processing, though, we would see a big performance gain
// by specifying hardware vertex processing.
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&AAA, &g_pd3dDevice ) ) )
{
// return E_FAIL;
}
// Device state would normally be set here
// return S_OK;
}
这么些编译可以过,但问题出在任何文件中#include "MyDirectx.h"就会出现错误
error C2065: “AAA”: 未声明的标识符
就算从源代码中找到定义重新现在前面也不行,比如说在前面定义了
typedef struct nb
{
UINT BackBufferWidth;
UINT BackBufferHeight;
D3DFORMAT BackBufferFormat;
UINT BackBufferCount;
D3DMULTISAMPLE_TYPE MultiSampleType;
DWORD MultiSampleQuality;
D3DSWAPEFFECT SwapEffect;
HWND hDeviceWindow;
BOOL Windowed;
BOOL EnableAutoDepthStencil;
D3DFORMAT AutoDepthStencilFormat;
DWORD Flags;
/* FullScreen_RefreshRateInHz must be zero for Windowed mode */
UINT FullScreen_RefreshRateInHz;
UINT PresentationInterval;
} D3DPRESENT_PARAMETERSF; //和D3DPRESENT_PARAMETERS一样的结构
下面换成
D3DPRESENT_PARAMETERSF AAA;
还是说AAA未定义,求解,使用的编译器是vc2008
[解决办法]
在前面加上 #include <d3d9.h>, 同时在工程的include目录里面加上d3d sdk安装后目录里的Include目录