gpt4 book ai didi

c++ - 使用 Directx 10 时,我得到了很多宏重新定义

转载 作者:行者123 更新时间:2023-12-04 06:39:33 26 4
gpt4 key购买 nike

我是使用 Visual Studio 2012 和 Directx 10 的 Windows 7。

问题是当我编译时,我得到了很多宏重定义错误

这是我的代码:

#include <windows.h>
#include <tchar.h>
#include <d3d.h>
#include <d3d10.h>


HINSTANCE hInstance; // Hold application instance
HWND wndHandle; // Hold window instance
ID3D10Device *mDevice = NULL;
IDXGISwapChain *mSwapChain = NULL;
ID3D10RenderTargetView *mRenderTargetView = NULL;

int width = 1024;
int height = 1024;
bool InitWindow( HINSTANCE hInstance, int width, int height );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
bool initD3D();
void Render();

int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow )
{
// Initialize the window
if ( !InitWindow( hInstance, width, height ) )
{
return false;
}
// main message loop:
MSG msg = {0};
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Additional game logic can be called from here
}
return (int) msg.wParam;
}



bool InitWindow(HINSTANCE hInstance, int width, int height)
{
WNDCLASSEX wcex;
// Fill in the WNDCLASSEX structure. This describes how the window
// will look to the system
wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
wcex.style = CS_HREDRAW | CS_VREDRAW; // the class style
wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
wcex.cbClsExtra = 0; // extra bytes to allocate for this class
wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
wcex.hInstance = hInstance; // handle to the application instance
wcex.hIcon = 0; // icon to associate with the application
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); // the default cursor to use
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // the background color
wcex.lpszMenuName = NULL; // the resource name for the menu
wcex.lpszClassName = TEXT("DirectXExample"); // the class name being created
wcex.hIconSm = 0; // the handle to the small icon
RegisterClassEx(&wcex);

// Resize the window
RECT rect = { 0, 0, width, height };
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
// create the window from the class above
wndHandle = CreateWindow(TEXT("DirectXExample"),
TEXT("DirectXExample"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
if (!wndHandle)
{
return false;
}

// Display the window on the screen
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Check any available messages from the queue
switch (message)
{
// Allow the user to press the Escape key to end the application
case WM_KEYDOWN:
switch(wParam)
{
// Check if the user hit the Escape key
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
break;
// The user hit the close button, close the application
case WM_DESTROY:
PostQuitMessage(0);
break;
}
// Always return the message to the default window procedure for further processing
return DefWindowProc(hWnd, message, wParam, lParam);
}

bool initD3D()
{
DXGI_SWAP_CHAIN_DESC sd;
sd.BufferDesc.Width = width; // use window's client area dims
sd.BufferDesc.Height = height;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
// No multisampling.
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
sd.OutputWindow = wndHandle;
sd.Windowed = true;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Flags = 0;


if ( FAILED (D3D10CreateDeviceAndSwapChain ( NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL,
0, D3D10_SDK_VERSION, &sd, mSwapChain, &mDevice ) ) )
{
MessageBox ( wndHandle, L"Failed to create device and swapchain", L"error", MB_OK );
return FALSE;
}

// get the back buffer from the swap chain
ID3D10Texture2D *Backbuffer = NULL;
HRESULT hr = mSwapChain->GetBuffer (0, __uuidof(ID3D10Texture2D), (LPVOID*)&Backbuffer);

if ( hr != S_OK)
{
return false;
}

// Create the render target view
hr = mDevice->CreateRenderTargetView ( Backbuffer, NULL, &mRenderTargetView);

// Release Back Buffer
Backbuffer -> Release();

// Make sure the render target view was created successfully
if ( hr!= S_OK)
{
return false;
}

// Set render target
mDevice -> OMSetRenderTargets ( 1, &mRenderTargetView, NULL);

// Create Viewport
D3D10_VIEWPORT viewport;
viewport.Width = width;
viewport.Height = height;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;

// Set the Viewport
mDevice->RSSetViewports (1, &viewport);

return true;
}

void Render()
{
if ( mDevice != NULL )
{
// Clear the back buffer
mDevice->ClearRenderTargetView(mRenderTargetView, color);

// Present
mSwapChain->Present(0,0);
}
}

当我编译时,我得到了很多宏重定义错误:

1> Source.cpp 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(12): warning C4005: 'DXGI_STATUS_OCCLUDED' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49449) :'DXGI_STATUS_OCCLUDED' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(13): warning C4005: 'DXGI_STATUS_CLIPPED' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49458) : 'DXGI_STATUS_CLIPPED' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(14): warning C4005: 'DXGI_STATUS_NO_REDIRECTION' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49467) : 'DXGI_STATUS_NO_REDIRECTION' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(15): warning C4005: 'DXGI_STATUS_NO_DESKTOP_ACCESS' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49476) : 'DXGI_STATUS_NO_DESKTOP_ACCESS' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(16): warning C4005: 'DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49485) : 'DXGI_STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(17): warning C4005: 'DXGI_STATUS_MODE_CHANGED' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49494) :'DXGI_STATUS_MODE_CHANGED' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(18): warning C4005: 'DXGI_STATUS_MODE_CHANGE_IN_PROGRESS' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49503) : 'DXGI_STATUS_MODE_CHANGE_IN_PROGRESS' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(21): warning C4005: 'DXGI_ERROR_INVALID_CALL' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49518) : 'DXGI_ERROR_INVALID_CALL' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(22): warning C4005: 'DXGI_ERROR_NOT_FOUND' : 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(26): warning C4005: 'DXGI_ERROR_DEVICE_HUNG' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49563) : 'DXGI_ERROR_DEVICE_HUNG' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(27): warning C4005: 'DXGI_ERROR_DEVICE_RESET' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49573) : 請'DXGI_ERROR_DEVICE_RESET' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(28): warning C4005: 'DXGI_ERROR_WAS_STILL_DRAWING' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49582) : 請'DXGI_ERROR_WAS_STILL_DRAWING' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(29): warning C4005: 'DXGI_ERROR_FRAME_STATISTICS_DISJOINT' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49592) : 請'DXGI_ERROR_FRAME_STATISTICS_DISJOINT' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(30): warning C4005: 'DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49601) : 'DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(33): warning C4005: 'DXGI_ERROR_NOT_CURRENTLY_AVAILABLE' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49629) :'DXGI_ERROR_NOT_CURRENTLY_AVAILABLE' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(34): warning C4005: 'DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49639) : 'DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED' 1>c:\program files\microsoft directx sdk (june 2010)\include\dxgitype.h(35): warning C4005: 'DXGI_ERROR_REMOTE_OUTOFMEMORY' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49648) : 'DXGI_ERROR_REMOTE_OUTOFMEMORY' 1>c:\program files\microsoft directx sdk (june 2010)\include\d3d10.h(608): warning C4005: 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49793) : 'D3D10_ERROR_TOO_MANY_UNIQUE_STATE_OBJECTS' 1>c:\program files\microsoft directx sdk (june 2010)\include\d3d10.h(609): warning C4005: 'D3D10_ERROR_FILE_NOT_FOUND' : 1> c:\program files\windows kits\8.0\include\shared\winerror.h(49802) : 1>c:\users\peter\documents\visual studio 2012\projects\win32project2\win32project2\source.cpp(16): error C4430: 1>c:\users\peter\documents\visual studio 2012\projects\win32project2\win32project2\source.cpp(16): error C2146: 1>c:\users\peter\documents\visual studio 2012\projects\win32project2\win32project2\source.cpp(16): warning C4244: 1>c:\users\peter\documents\visual studio 2012\projects\win32project2\win32project2\source.cpp(190): error C2664: 'ID3D10Device::ClearRenderTargetView' :

最佳答案

这些不是真正的错误,而是警告。尽管如此,他们还是让你觉得你很糟糕 =)

微软弃用风格

DirectX SDK 已合并到 Windows SDK(从 Windows 8 SDK 开始)。某些功能已被弃用和删除。

您正在混合 2 个 SDK:

  • c:\program files\microsoft directx sdk (june 2010)\include\ 中的旧 DirectX SDK
  • c:\program files\windows kits\8.0\include\shared\ 中的新 Windows SDK

  • 不建议在新项目中使用 DirectX SDK 头文件或库。因此,在项目设置中 -> "VC++ Directories" -> "Include Directories"删除对 DirectX SDK 的引用。

    如果您仍然需要一些旧功能(例如编译旧教程示例或旧项目),请包含 DirectX SDK header ,但更改项目设置 -> "General" -> "Platform Toolset""Visual Studio 2012 - Windows XP (v110_xp)" .

    想知道更多? Yes/不。

    关于c++ - 使用 Directx 10 时,我得到了很多宏重新定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19336841/

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