Visual c++ visualc&x2B+;DirectX编译错误
有人能帮我解决这个错误吗? 我已经链接到了d3d10.lib和d3dx10.lib 我是directX的新手,我一直在关注wendy jones directX 10 toturial 1> t1.obj:错误LNK2019:未解析的外部符号_D3D10CreateDeviceAndSwapChain@32在函数“boolcdecl InitDirect3D(struct HWND*,int,int)”中引用(?InitDirect3D@@YA_npauwnd__@@HH@Z) 1> C:\Users\Ehsan\Documents\Visual Studio 2010\Projects\DirectX\t1\Debug\t1.exe:致命错误LNK1120:1未解析的外部 源代码:Visual c++ visualc&x2B+;DirectX编译错误,visual-c++,directx-10,Visual C++,Directx 10,有人能帮我解决这个错误吗? 我已经链接到了d3d10.lib和d3dx10.lib 我是directX的新手,我一直在关注wendy jones directX 10 toturial 1> t1.obj:错误LNK2019:未解析的外部符号_D3D10CreateDeviceAndSwapChain@32在函数“boolcdecl InitDirect3D(struct HWND*,int,int)”中引用(?InitDirect3D@@YA_npauwnd__@@HH@Z) 1> C:\Us
// t1.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "windows.h"
#include "tchar.h"
#include <d3d10.h>
#include <d3dx10.h>
// Global Variables:
HINSTANCE hInst; // global handle to hold the application instance
HWND wndHandle; // global variable to hold the window handle
int width = 640;
int height = 480;
// Direct3D global vars
ID3D10Device * pD3DDevice = NULL;
IDXGISwapChain * pSwapChain = NULL;
ID3D10RenderTargetView * pRenderTargetView = NULL;
// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
bool InitWindow( HINSTANCE hInstance, int width, int height );
void Render();
void ShutDownDirect3D();
bool InitDirect3D(HWND hWnd, int width, int height);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg = {0};
// Perform application initialization:
if ( !InitWindow( hInstance, width, height ) )
{
return FALSE;
}
// called after creating the window
if(!InitDirect3D(wndHandle, width, height))
{
return FALSE;
}
//hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_T1));
// Main message loop:
while (WM_QUIT != msg.message)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Call the render function
Render();
}
ShutDownDirect3D();
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;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
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 furtherprocessing
return DefWindowProc(hWnd, message, wParam, lParam);
}
/*******************************************************************
* InitDirect3D
* Initializes Direct3D
* Inputs - Parent window handle - HWND,
Window width - int
Window height - int
Updating the Code 31
* Outputs - true if successful, false if failed - bool
*******************************************************************/
bool InitDirect3D(HWND hWnd, int width, int height)
{
// Create the clear the DXGI_SWAP_CHAIN_DESC structure
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
// Fill in the needed values
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hWnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = TRUE;
// Create the D3D device and the swap chain
HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL,
D3D10_DRIVER_TYPE_REFERENCE,
NULL,
0,
D3D10_SDK_VERSION,
&swapChainDesc,
&pSwapChain,
&pD3DDevice);
// Error checking. Make sure the device was created
if (hr != S_OK)
{
return false;
}
// Get the back buffer from the swapchain
ID3D10Texture2D * pBackBuffer;
hr = pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*) &pBackBuffer);
if (hr != S_OK)
{
return false;
}
// create the render target view
hr = pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView);
// release the back buffer
pBackBuffer->Release();
// Make sure the render target view was created successfully
if (hr != S_OK)
{
return false;
}
// set the render target
pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
// create and set the viewport
D3D10_VIEWPORT viewport;
viewport.Width = width;
viewport.Height = height;
viewport.MinDepth = 0.0f;
viewport.MaxDepth = 1.0f;
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
pD3DDevice->RSSetViewports(1, &viewport);
return true;
}
/*******************************************************************
* ShutdownDirect3D
* Closes down and releases the resources for Direct3D
34 Chapter 2 n Your First DirectX Program
* Inputs - void
* Outputs - void
*******************************************************************/
void ShutDownDirect3D()
{
// release the rendertarget
if(pRenderTargetView)
{
pRenderTargetView->Release();
}
// release the swapchain
if(pSwapChain)
{
pSwapChain->Release();
}
// release the D3D Device
if(pD3DDevice)
{
pD3DDevice->Release();
}
}
/*******************************************************************
* Render
* All drawing happens in the Render function
* Inputs - void
* Outputs - void
*******************************************************************/
void Render()
{
if (pD3DDevice != NULL)
{
// clear the target buffer
pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));
// All drawing will go here.
// display the next item in the swap chain
pSwapChain->Present(0, 0);
}
}
//t1.cpp:定义应用程序的入口点。
//
#包括“stdafx.h”
#包括“windows.h”
#包括“tchar.h”
#包括
#包括
//全局变量:
HINSTANCE hInst;//保存应用程序实例的全局句柄
HWND wndHandle;//用于保存窗口句柄的全局变量
整数宽度=640;
内部高度=480;
//Direct3D全局变量
ID3D10Device*pD3DDevice=NULL;
IDXGISwapChain*pSwapChain=NULL;
ID3D10RenderTargetView*pRenderTargetView=NULL;
//转发此代码模块中包含的函数声明:
LRESULT回调WndProc(HWND、UINT、WPARAM、LPARAM);
bool InitWindow(HINSTANCE HINSTANCE,int-width,int-height);
void Render();
void ShutDownDirect3D();
bool InitDirect3D(HWND-HWND,int-width,int-height);
int APIENTH_tWinMain(HINSTANCE HINSTANCE),
HINSTANCE HPPrevenstance,
LPTSTR lpCmdLine,
国际展览(nCmdShow)
{
//TODO:将代码放在这里。
MSG={0};
//执行应用程序初始化:
如果(!InitWindow(高度、宽度、高度))
{
返回FALSE;
}
//创建窗口后调用
如果(!InitDirect3D(wndHandle、宽度、高度))
{
返回FALSE;
}
//hAccelTable=加载加速器(hInstance、MAKEINTRESOURCE(IDC_T1));
//主消息循环:
while(WM_QUIT!=msg.message)
{
while(peek消息(&msg,NULL,0,0,PM_REMOVE)==TRUE)
{
翻译信息(&msg);
发送消息(&msg);
}
//调用render函数
Render();
}
ShutDownDirect3D();
返回(int)msg.wParam;
}
bool InitWindow(HINSTANCE HINSTANCE,int-width,int-height)
{
WNDCLASSEX wcex;
//填写WNDCLASSEX结构。这描述了如何
//我们将关注这个系统
wcex.cbSize=sizeof(WNDCLASSEX);//结构的大小
wcex.style=CS_HREDRAW | CS_VREDRAW;//类样式
wcex.lpfnWndProc=(WNDPROC)WNDPROC;//窗口过程回调
wcex.cbClsExtra=0;//要为此类分配的额外字节
wcex.cbWndExtra=0;//要为此实例分配的额外字节
wcex.hInstance=hInstance;//应用程序实例的句柄
wcex.hIcon=0;//与应用程序关联的图标
wcex.hCursor=LoadCursor(NULL,IDC_箭头);//要使用的默认光标
wcex.hbrBackground=(HBRUSH)(颜色窗口+1);//背景色
wcex.lpszMenuName=NULL;//菜单的资源名称
wcex.lpszClassName=TEXT(“DirectXExample”);//正在创建的类名
wcex.hIconSm=0;//小图标的句柄
注册类别(&wcex);
//调整窗口大小
RECT RECT={0,0,宽度,高度};
AdjustWindowRect(&rect,WS_OVERLAPPEDWINDOW,FALSE);
//从上面的类创建窗口
wndHandle=CreateWindow(文本(“DirectXExample”),
文本(“DirectXExample”),
WS_重叠窗口,
CW_使用默认值,
CW_使用默认值,
右,右,左,
rect.bottom-rect.top,
无效的
无效的
hInstance,
无效);
如果(!wndHandle)
{
返回false;
}
//在屏幕上显示窗口
展示窗口(wndHandle、SW_SHOW);
更新窗口(wndHandle);
返回true;
}
//
//功能:WndProc(HWND、UINT、WPARAM、LPARAM)
//
//用途:处理主窗口的消息。
//
//WM_命令-处理应用程序菜单
//WM_绘制-绘制主窗口
//WM_DESTROY-发布退出消息并返回
//
//
LRESULT回调WndProc(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM)
{
//检查队列中的任何可用消息
开关(信息)
{
//允许用户按Escape键结束应用程序
案例WM_键控:
交换机(wParam)
{
//检查用户是否按了退出键
案件VK_逃逸:
PostQuitMessage(0);
打破
}
打破
//用户点击关闭按钮,关闭应用程序
案例WM_销毁:
PostQuitMessage(0);
打破
}
//始终将消息返回到默认窗口过程以进行进一步处理
返回DefWindowProc(hWnd、message、wParam、lParam);
}
/*******************************************************************
*InitDirect3D
*初始化Direct3D
*输入-父窗口句柄-HWND,
窗口宽度-整数
窗高-整数
更新代码31
*输出-成功时为真,失败时为假-布尔
*******************************************************************/
bool InitDirect3D(HWND-HWND,int-width,int-height)
{
//创建清除DXGI\u交换\u链\u描述结构的
DXGI交换链描述交换链;
零内存(&swapChainDesc,sizeof(swapChainDesc));
//填写所需的值
swapChainDesc.BufferCount=1;
swapChainDesc.BufferDesc.Width=宽度;
swapChainDesc.BufferDesc.Height=高度;
swapChainDesc.BufferDesc.Format=DXGI_Format_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator=60;
swapChainDesc.BufferDesc.RefreshRate.Denominor=1;
swapChainDesc.BufferUsage=DXGI\u USAGE\u RENDER\u TARGET\u输出;
swapChainDesc.OutputWindow=hWnd;
swapChainDesc.SampleDesc.Count=1;
swapChainDesc.SampleDesc.Quality=0;
swapChainDesc.Windowed=TRUE;
//创建D3D设备和交换链
HRESULT hr=D3D10已创建