【发布时间】:2014-08-10 03:32:05
【问题描述】:
所以我按照一本书上的说明来创建一个 d3d 对象。但是,当我尝试编译代码时,它在 d3d11shader.h 中给了我一些奇怪的错误。
在d3dshader.h里面,
#include "d3dcommon.h"
//other stuff
typedef struct _D3D11_SIGNATURE_PARAMETER_DESC
{
LPCSTR SemanticName;
UINT SemanticIndex;
UINT Register;
D3D_NAME SystemValueType;
D3D_REGISTER_COMPONENT_TYPE ComponentType;
BYTE Mask;
BYTE ReadWriteMask;
UINT Stream;
D3D_MIN_PRECISION MinPrecision; //Errors here
} D3D11_SIGNATURE_PARAMETER_DESC;
详情:
(1) Error 29 error C2146: syntax error : missing ';' before identifier 'MinPrecision' c:\program files (x86)\windows kits\8.0\include\um\d3d11shader.h 54
(2) Error 30 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\program files (x86)\windows kits\8.0\include\um\d3d11shader.h 54
这很奇怪,因为 d3dcommon.h 和 d3d11shader.h 文件都是在 Windows SDK 和 DirectX SDK 中定义的,所以我无法更改其中的任何内容。谁能告诉我如何解决它?任何意见都在这里表示赞赏。
这是我的 Source.cpp 中的代码,这些代码直接从 Frank Luna 的《使用 DirectX11 进行 3D 游戏编程》一书中复制而来。
#include "d3dApp.h"//This header file is provided by the book
class InitDirect3DApp : public D3DApp
{
public:
InitDirect3DApp(HINSTANCE hInstance);
~InitDirect3DApp();
bool Init();
void OnResize();
void UpdateScene(float dt);
void DrawScene();
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
PSTR cmdLine, int showCmd)
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
InitDirect3DApp theApp(hInstance);
if( !theApp.Init() )
return 0;
return theApp.Run();
}
Init Direct3DApp::InitDirect3DApp(HINSTANCE hInstance)
: D3DApp(hInstance)
{
}
InitDirect3DApp::~InitDirect3DApp()
{
}
bool InitDirect3DApp::Init()
{
if(!D3DApp::Init())
return false;
return true;
}
void InitDirect3DApp::OnResize()
{
D3DApp::OnResize();
}
void InitDirect3DApp::UpdateScene(float dt)
{
}
void InitDirect3DApp::DrawScene()
{
assert(md3dImmediateContext);
assert(mSwapChain);
md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Blue));
md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
HR(mSwapChain->Present(0, 0));
}
我注意到的另一件奇怪的事情是,有时当我转到 D3D_MIN_PRECISION 的定义并将我引导至 d3dcommon.h 时,d3dcommon.h 中的代码根本没有突出显示。 Visual Studio 会自动突出显示所有其他文件,但不会自动突出显示这个文件。所以我只是假设它有时无法识别此特定头文件中的代码。
另外,我刚才在编译代码时,除了前两个之外,还弹出另一个错误:
31 IntelliSense: identifier "D3D_MIN_PRECISION" is undefined c:\Program Files (x86)\Windows Kits\8.0\Include\um\d3d11shader.h 54
仅供参考,我在 Windows 8.1 机器上使用 vs2012。非常感谢!
【问题讨论】:
-
也许可以向我们展示您在其中使用此结构的代码?
-
@rashmatash 感谢您的回复。通过在 vs2012 中使用“查找所有引用”,我可以看出这个结构到目前为止没有在任何地方使用。我还发布了我的 Source.cpp 以防万一您需要它。谢谢!
-
很抱歉,我真的不知道是什么导致了这个问题。我唯一能想到的是,也许某处有一个名为
MinPrecision的宏定义会干扰这个结构的声明。可以肯定的是,在你的编辑器中给所有的宏设置一个明亮的颜色,看看有没有什么东西亮起来? -
@rashmatash 我很确定 Windows Kit SDK 中有一个 d3dcommon.h,DirectX SDK 中有一个 D3Dcommon.h。这两个文件中的大多数宏都是相同的,但 MinPrecision 仅在 d3dcommon.h 中定义。据我记得,头文件的名称在 C++ 中不区分大小写。这会是造成这一切混乱的原因吗?
标签: c++ visual-studio-2012 directx direct3d